AI Customization Rules for Agentforce for Developers

AI Customization Rules are a way to set up how AI-generated code looks and behaves across files and languages in Agentforce for Developers. This feature provides control, consistency, and customization over AI-generated code through familiar project structures and Markdown-based configuration. Customization rules are enabled by default and are currently available in:

  • Dev Assistant
  • Apex Test Case Generation

AI customization rules are a feature of Agentforce for Developers and apply to the Salesforce project structure. You must have a basic understanding of Markdown syntax to use these rules.

FeatureDescriptionUse Case
Markdown-based RulesDefine rules using simple Markdown syntax.Create consistent coding standards across your project.
File Pattern TargetingApply rules to specific file types using glob patterns.Enforce standards for specific languages or frameworks.
Automatic Rule ApplicationRules are automatically picked up by AI features.Ensure consistent code generation across all AI interactions.

To set up custom rules:

  1. Create a .sfdx/a4d/rules/ directory in your Salesforce DX project root.
  2. Create Markdown files for your rules that follow our given format.

Rules are automatically detected and applied when you use Agentforce for Developers.

AI Customization rules are enabled by default.

To enable or disable the AI Customization Rules feature from Settings:

  1. Select File > Preferences > Settings (Windows or Linux) or Code > Settings > Settings (macOS).
  2. Under Agentforce for Developers, select Enable Ai Custom Rules and then select the feature for which you want to enable or disable rules.

Use this simple rules format to create your custom rules:

Here are some sample customization rules that you can use as guidelines to create your own rules. Applying these rules ensures uniform code quality, easier maintenance, and improved collaboration. The Dev Assistant applies these best practices automatically whenever code is generated, reducing the need for manual reviews and refactoring.

This example Apex Best Practices rule file defines a comprehensive set of coding conventions and best practices for all Apex classes (_.cls) and triggers (_.trigger). It ensures consistency, readability, and maintainability across your Salesforce codebase by enforcing naming conventions, code structure, and key Salesforce coding guidelines.

This LWC Template Structure rule file defines guidelines to ensure consistent structure and readability in Lightning Web Component (LWC) HTML templates. By enforcing these conventions, you ensure that your LWC templates follow best practices and remain easy to understand and maintain across your team.

Here are some helpful tips to keep in mind while creating custom rules:

Stick to one file type per rule – This practice makes it easier to manage your rules and reduces confusion.

Be clear and to the point – Simple, straightforward rules are easier to understand and follow.

Try them out – Test your rules with different AI features to make sure they work as expected.

Keep them fresh – Revisit and update your rules regularly to stay aligned with evolving project needs.

AI customization rules offer a simple way to manage behavior using pattern-based settings, but there are a few limitations to keep in mind in this early version:

File-Based Matching Only: Rules are restricted to file-level pattern matching and don't support more dynamic or context-aware criteria.

Security Restrictions on Rules: Complex or overly broad rules are ignored or rejected to maintain security and stability.

No User Interface in MVP: The minimum viable product (MVP) doesn't have a user interface for creating, editing, or validating rules; all configuration must be done manually.

Internal Handling of Tokens and Prioritization: Token management and rule prioritization are managed internally by the system and aren't exposed for user control.

No Custom Rules for Slash Commands: Currently, AI customization rules don't apply to generations from slash commands.

We expect these limitations to evolve in future releases.

AI Customization Rules are designed with safety in mind to help prevent prompt injection and ensure secure usage:

Clean and safe – Rules are automatically cleaned up to remove harmful patterns.

Targeted application – Rules apply only to the specific file types they’re meant for.

Smart filtering – For security reasons, any rules that are too risky or too broad are automatically skipped..