What makes an effective rule
Include facts the agent cannot infer from the code on its own. Describe your codebase so the agent understands what it reads and which attacks are realistic:- The primary languages and frameworks you use on the frontend and backend.
- The entry points where untrusted input arrives, such as the package that holds your HTTP handlers.
- The authentication and authorization enforcement points, such as the middleware that protects your API routes and the file it lives in.
- The trust boundaries in your code, identified by file or directory.
- The sinks and sanitizers specific to your project, named exactly.
- The sources of secrets and configuration, such as a secrets manager loaded at boot rather than values hardcoded in source.
- The deployment shape, such as a static frontend with all authorization enforced server-side.
What not to include in a rule
AI context rules are reference evidence, not instructions, so the agent ignores anything that tries to override its built-in behavior. Do not include the following:- Instructions to turn off a detection category, such as telling the agent not to report SQL injection.
- Instructions to ignore real secrets, such as hardcoded credentials. The agent always reports them.
- Demands for a finding that the code evidence does not support.
- Generic security advice, such as OWASP, CWE, or phrases like validate all input. It says nothing about your code, so the agent ignores it.
- Secrets, tokens, private keys, personal data, or verbatim source code. Reference sensitive code by its file path and symbol name instead.
Automatic context from repository files
During a scan, Endor Labs also builds context automatically. It reads guidance files in your repository along with prior reviewer decisions, grounds them against your code, and uses them alongside the rules you create. Reviewer feedback takes precedence over the rules you write, and the most recent decision takes precedence when reviewers disagree over time. By default, a scan reads these files when they are within the scan scope:CLAUDE.md, and files under.claude/agents/and.claude/rules/.AGENTS.md..cursorrules, and files under.cursor/rules/..github/copilot-instructions.md.SKILL.mdfiles, such as.claude/skills/<name>/SKILL.md.memory.md.
Create an AI context rule
Create a rule to give the agent guidance about your code. You can enable or disable a rule at any time after you create it. To create an AI context rule:- Select Policies from the user menu.
- Select AI Context Rules.
- Select Create AI Context.
- Enter the following details:
- AI Context Name: A name that identifies the rule.
- Context: The guidance the agent reads. Describe the codebase, the conditions to look for, or background about the project.
- Under Scope, select the namespace the rule applies to. By default, the rule applies to all projects in the namespace.
- To limit the rule to specific projects, use Inclusions:
- Click Add more under Inclusions.
- Select the projects you want to include.
- Click Update.
- Optionally, enter the tags of the projects you want to include.
- To exclude specific projects, use Exclusions:
- Click Add more under Exclusions.
- Select the projects you want to exclude.
- Click Update.
- Optionally, enter the tags of the projects you want to exclude.
- Click Create AI Context.

Manage AI context rules
You can edit, clone, delete, enable, or disable a rule at any time. Update or delete a rule when the code it describes moves or changes, so the agent does not work from stale guidance. Edit a rule to update its name, context, or scope.- Select Policies from the user menu.
- Select AI Context Rules.
- Click the vertical three dots next to the rule you want to edit.
- Select Edit.
- Update the AI context name, context, inclusions, or exclusions.
- Click Update AI Context.
- Select Policies from the user menu.
- Select AI Context Rules.
- Click the vertical three dots next to the rule you want to clone and select Clone.
- Update the AI context name, context, inclusions, and exclusions for the new rule.
- Click Create AI Context.
- Select Policies from the user menu.
- Select AI Context Rules.
- Click the vertical three dots next to the rule you want to remove and select Delete.
When rules take effect
The detection agent reads AI context rules at the start of a scan. A new or updated rule therefore applies to the next scan, not to findings that already exist. Most scans are incremental. An incremental scan re-evaluates only the functions in files that changed since the last full index. Existing findings outside those files keep their previous verdict. A code change surfaces the effect of a rule only for findings in the files it touches. To re-evaluate every finding against your current rules, run a full detection scan with the--ai-sast-rescan flag.
ENDOR_SCAN_AI_SAST_RESCAN=true to the additional environment variables of the project’s scan profile. Remove it after the full scan completes so later scans return to incremental mode.
Example AI context rules
Adapt the names and paths in these examples to your own code.Authentication happens in another service
Authentication happens in another service
Authentication is handled upstream, so the agent stops flagging missing authentication in this service but keeps reporting missing resource authorization.
A dependency provides the sanitizer
A dependency provides the sanitizer
A shared library sanitizes HTML, so the agent suppresses XSS findings on output that passes through it while still reporting sinks that bypass it.
A required authentication mechanism for every endpoint
A required authentication mechanism for every endpoint
Every protected endpoint must use a specific middleware, so the agent reports routes registered without it and leaves public routes alone.
Tenant boundary fields
Tenant boundary fields
Specific fields enforce tenant isolation, so the agent reports routes that scope queries by user instead of by tenant.
Custom admin model and low-noise scope
Custom admin model and low-noise scope
Admin actions need two separate checks and some directories are out of scope, so the agent catches incomplete admin checks and suppresses findings in non-production paths.