Platform and security engineering teams use this prompt to help developers understand why a static analysis rule fired on their code. Raw linter and SAST output often provides only a rule ID, a severity level, and a line number. Developers who do not understand the rule's intent are more likely to ignore findings, apply incorrect fixes, or suppress the rule entirely. This prompt produces a structured, plain-language explanation that connects the flagged code pattern to the rule's purpose, the potential impact of the violation, and the principle being enforced. It is designed to be wired into CI/CD pipelines, IDE integrations, or internal developer portals where every finding needs a clear, consistent explanation before it reaches a human reviewer.
Prompt
Rule Fire Explanation Prompt for Linter Output

When to Use This Prompt
Use this prompt to generate plain-language explanations for static analysis findings before they reach a developer's queue.
The ideal user is a platform engineer or DevSecOps practitioner building a developer-facing triage workflow. Required context includes the rule metadata (ID, short description, severity, category), the flagged code snippet with surrounding lines, and optionally the file path and language. The prompt works best when the rule has a documented purposeāif the rule is a custom internal rule without clear intent, the explanation quality degrades and the output should be flagged for human review. Do not use this prompt for findings that require exploitability assessment, risk ranking, or deduplication; those are separate workflows with their own prompts and evaluation criteria.
Before wiring this into a pipeline, define your evaluation criteria: does the explanation accurately capture the rule's intent? Does it connect the specific code pattern to the principle being enforced? Does it avoid hallucinating fix suggestions when none are appropriate? Run a batch of known findings through the prompt and have a security engineer review the explanations for correctness. Flag any explanation that introduces new technical claims not present in the rule definition or code context. For high-severity findings in regulated environments, always route the explanation through a human approval step before it reaches the developer.
Use Case Fit
Where the Rule Fire Explanation Prompt delivers value and where it introduces risk. Use these cards to decide whether this prompt fits your workflow before integrating it into a developer-facing tool or CI pipeline.
Good Fit: Developer Onboarding to Static Analysis
Use when: platform teams are rolling out new linter rules or SAST tools to developers unfamiliar with the rule set. Guardrail: pair explanations with links to internal coding standards and allow developers to submit feedback when an explanation misses the mark.
Bad Fit: Unreviewed Security Remediation
Avoid when: the explanation could be interpreted as a complete security assessment or a substitute for manual review of critical vulnerabilities. Guardrail: always route explanations for high-severity security findings through a human reviewer before they reach the developer.
Required Inputs: Code Context and Rule Metadata
What to watch: explanations degrade when the prompt receives only a line number and rule ID without the surrounding code, rule description, or severity. Guardrail: require the flagged code snippet, the rule's intended purpose, and the violation message as minimum inputs before generating an explanation.
Operational Risk: Hallucinated Rule Intent
What to watch: the model may invent a plausible but incorrect rationale for why a rule fired, especially for custom or poorly documented rules. Guardrail: validate a sample of explanations against the actual rule implementation and maintain a feedback loop for developers to flag inaccurate explanations.
Operational Risk: Explanation Drift Across Rule Updates
What to watch: when linter rules change, cached or previously generated explanations may become stale and mislead developers. Guardrail: version explanations alongside rule definitions and regenerate explanations when rule logic, severity, or policy intent changes.
Bad Fit: Fully Automated Fix Generation
Avoid when: the prompt is expected to produce the code fix itself rather than explain the violation. Explanation and remediation are separate concerns. Guardrail: keep this prompt focused on explanation only; pair it with a separate, tested remediation prompt when fix suggestions are needed.
Copy-Ready Prompt Template
A ready-to-use prompt template that instructs the model to explain why a linter rule fired on a specific piece of code.
This prompt template is the core instruction you send to the model. It is designed to take a linter rule definition and the flagged code snippet, then produce a structured, developer-friendly explanation. The output is organized into four clear sections: the rule's intent, a pattern analysis of the flagged code, the potential impact of leaving the code as-is, and the underlying software engineering principle being enforced. This structure ensures the explanation is both educational and actionable, helping developers understand not just what is wrong, but why it matters.
textYou are a senior developer educator and static analysis expert. Your task is to explain why a specific static analysis rule flagged a piece of code. Your explanation must be accurate, concise, and educational, helping a developer understand the reasoning behind the rule and how to fix the issue. ## INPUT [RULE_NAME]: The name of the linter rule that fired. [RULE_DESCRIPTION]: The full description of the rule from the tool's documentation. [FLAGGED_CODE]: The exact code snippet that triggered the rule. [CODE_LANGUAGE]: The programming language of the flagged code. ## OUTPUT FORMAT Produce a JSON object with the following structure. Do not include any text outside the JSON object. { "rule_intent": "A plain-language explanation of what the rule is designed to detect and prevent. Describe the class of bug, security vulnerability, or maintainability issue it targets.", "pattern_analysis": "A specific analysis of why the provided [FLAGGED_CODE] matches the rule's pattern. Point to the exact lines, variables, or structures that triggered the rule. Explain the mechanism of the problem in this specific instance.", "potential_impact": "A clear description of the concrete negative consequences that could occur if this code pattern is not fixed. Mention specific risks like runtime errors, security breaches, data corruption, or performance degradation. If the risk is low, state that clearly.", "underlying_principle": "The broader software engineering or security principle this rule enforces (e.g., 'Principle of Least Privilege', 'Fail Fast', 'Single Responsibility'). Explain how this principle applies to the flagged code." } ## CONSTRAINTS - Do not hallucinate. Base your analysis strictly on the provided [RULE_DESCRIPTION] and [FLAGGED_CODE]. - If the [FLAGGED_CODE] appears to be a false positive, explain why it matches the pattern but note any mitigating context that might make it safe. - Use clear, jargon-free language suitable for a developer who may not be an expert in static analysis. - The output must be valid JSON.
To adapt this template, replace the placeholders in the ## INPUT section with data from your CI/CD pipeline or static analysis tool. The [RULE_NAME] and [RULE_DESCRIPTION] can be pulled directly from your tool's rule database. The [FLAGGED_CODE] should be the specific lines from the pull request diff that triggered the finding, not the entire file. Before integrating, test this prompt with a golden dataset of known true positives and false positives to ensure the pattern_analysis is precise and the potential_impact is not over- or under-stated. For high-security contexts, always route outputs where the model identifies a potential_impact of 'security breach' for mandatory human review before sending to the developer.
Prompt Variables
Each placeholder must be populated before the prompt is sent to the model. Missing or incorrect variables produce unreliable explanations.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[RULE_ID] | Identifies the specific static analysis rule that fired | semgrep.python.flask.open-redirect | Must match a rule ID in your SAST tool registry. Validate against the active ruleset before sending. |
[RULE_DESCRIPTION] | The official description of the rule from the tool's documentation | Detects unvalidated redirects using Flask's redirect() with user-controlled input | Must be non-empty and sourced from the canonical rule metadata. Null or placeholder text triggers a retry. |
[RULE_SEVERITY] | The severity level assigned by the static analysis tool | ERROR | Must be one of the allowed enum values: ERROR, WARNING, INFO, or NOTE. Reject unknown values. |
[CODE_SNIPPET] | The flagged code block with surrounding context lines | def profile_redirect():\n url = request.args.get('next')\n return redirect(url) | Must include at least 3 lines of context around the flagged line. Truncated or empty snippets abort the prompt. |
[FILE_PATH] | The repository-relative path to the file containing the finding | src/web/handlers/auth.py | Must be a valid relative path matching the repository structure. Absolute paths or paths outside the repo root are rejected. |
[LINE_NUMBER] | The line number where the rule fired | 42 | Must be a positive integer that exists within the file. Validate against the actual file length before sending. |
[LANGUAGE] | The programming language of the flagged code | python | Must be a supported language in your SAST tool. Use lowercase normalized names from the tool's language list. |
[FINDING_MESSAGE] | The raw message produced by the SAST tool for this finding | User-controlled request.args.get('next') flows into redirect() without sanitization | Must be non-empty. If the tool produced no message, use the rule description as a fallback and log the substitution. |
Implementation Harness Notes
How to wire the Rule Fire Explanation Prompt into a CI pipeline, developer portal, or linter bot so explanations are generated reliably and safely.
This prompt is designed to sit behind an API endpoint or a CI job that triggers when a static analysis tool (such as Semgrep, CodeQL, or ESLint) flags a finding on a pull request. The application layer is responsible for extracting the rule metadata, the offending code snippet, and the surrounding file context from the linter's output before assembling the prompt. Do not pass raw, untruncated linter logs directly to the model; pre-process the input to include only the specific finding, its location, and the rule definition. This keeps the prompt focused and prevents the model from hallucinating explanations for unrelated findings.
Validation and retries: Parse the model's output against a strict JSON schema that requires the fields rule_id, rule_intent, code_pattern_identified, potential_impact, principle_enforced, and fix_direction. If the output fails schema validation, retry once with a repair prompt that includes the validation error. If the second attempt also fails, log the failure and fall back to a static, rule-author-provided explanation. Model choice: Use a model with strong instruction-following and code reasoning capabilities, such as Claude 3.5 Sonnet or GPT-4o. Avoid smaller or older models that may conflate similar rules or invent plausible-sounding but incorrect explanations. Set temperature to 0.0ā0.2 to maximize factual consistency across repeated runs for the same finding.
Logging and review: Log every generated explanation alongside the input finding, the model version, and the prompt template version. For security-critical rules (e.g., those detecting credential leaks, SQL injection, or authentication bypass), route the explanation to a human reviewer before it is shown to the developer. This gate prevents a confidently wrong explanation from misleading a developer into an insecure fix. Integration points: In a developer portal, surface the explanation inline next to the finding. In a CI pipeline, post the explanation as a comment on the PR. In a chat bot, return the explanation as a structured message. In all cases, include a feedback mechanism (thumbs up/down) so the platform team can track explanation quality over time and identify rules that need better static descriptions or prompt tuning.
Expected Output Contract
The model must return a JSON object with these exact fields. Validate before surfacing to developers.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
rule_id | string | Must match the [RULE_ID] input exactly. Case-sensitive match required. | |
rule_name | string | Must be a non-empty string. Should match the human-readable name from the linter configuration. | |
flagged_code | string | Must be a non-empty string containing the exact code snippet that triggered the rule. Validate that the snippet is syntactically extractable from [CODE_SNIPPET]. | |
explanation | string | Must be 2-5 sentences in plain language. Validate length is between 50 and 500 characters. Must not contain markdown or code blocks. | |
rule_intent | string | Must describe the principle, policy, or risk the rule enforces. Validate that the intent is distinct from the explanation and does not simply restate the rule name. | |
potential_impact | string | Must be one of: 'security', 'reliability', 'maintainability', 'performance', 'style', 'compliance', 'correctness'. Validate against allowed enum values. | |
fix_suggestion | string | If present, must be a concrete, code-aware suggestion. Validate that the suggestion references specific identifiers or patterns from [CODE_SNIPPET]. Null allowed if no fix is applicable. | |
confidence | number | Must be a float between 0.0 and 1.0. Validate range. If confidence is below 0.7, a human review flag must be raised in the application layer. |
Common Failure Modes
What breaks first when generating rule fire explanations and how to guard against it.
Explanation Misses the Rule's Intent
What to watch: The model describes what the code does instead of why the rule flagged it. The explanation becomes a generic code summary with no connection to the security, correctness, or style principle the rule enforces. Guardrail: Include the rule's description, CWE mapping, and intended impact in the prompt context. Validate output against a checklist: does it name the principle, state the risk, and connect the code pattern to the rule's purpose?
Overconfident Severity Language
What to watch: The model uses absolute terms like 'critical vulnerability' or 'guaranteed exploit' when the finding is context-dependent or low-confidence. This causes developer alarm fatigue or unnecessary escalation. Guardrail: Require the prompt to use calibrated language tiers (likely, possible, unlikely). Add a confidence field to the output schema. Post-process to flag absolute claims that lack evidence from the rule definition or code context.
Hallucinated Fix Suggestions
What to watch: The model invents API calls, configuration options, or library functions that don't exist in the codebase or language. Developers waste time chasing fictional fixes. Guardrail: Constrain the prompt to explain the pattern and principle without generating specific code fixes unless the rule documentation includes verified examples. When fixes are requested, ground them in the actual code snippet provided, not general best practices.
Context Window Truncation Drops Key Evidence
What to watch: Large code snippets or multiple files push the flagged line and surrounding context out of the model's effective attention. The explanation references code that wasn't actually seen. Guardrail: Truncate input to the flagged line plus a fixed surrounding window (e.g., ±30 lines). If the rule requires cross-file analysis, include only the specific referenced symbols. Log when input was truncated so downstream consumers know the explanation scope.
Explanation Contradicts the Rule Definition
What to watch: The model produces a plausible-sounding explanation that directly contradicts the rule's documented purpose. For example, explaining a security rule as a style concern or vice versa. Guardrail: Include the rule definition as a non-negotiable grounding source in the system prompt. Add an eval step that checks semantic alignment between the explanation and the rule definition using an LLM judge or embedding similarity threshold.
False Positive Explanations Sound Confident
What to watch: When the finding is a false positive, the model still generates a detailed explanation of why the pattern is dangerous, misleading developers into accepting the finding as valid. Guardrail: Add a pre-classification step that asks the model to determine if the finding is a true positive, false positive, or uncertain before generating the explanation. For false positives, generate an explanation of why the rule misfired, not why the pattern is dangerous.
Evaluation Rubric
Run these checks against a golden dataset of 20-50 known findings with human-written reference explanations before shipping this prompt to developers.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Rule Intent Accuracy | Explanation correctly identifies the core principle or vulnerability class the rule enforces in >= 90% of cases. | Explanation describes a different rule's intent, misidentifies the vulnerability class, or states a generic security platitude. | Human A/B comparison against reference explanations. Flag if intent mismatch rate exceeds 10%. |
Code Pattern Grounding | Explanation references the specific flagged line, variable, or control flow pattern from [CODE_SNIPPET] in >= 95% of cases. | Explanation is generic with no reference to the actual code, or references a pattern not present in the snippet. | Automated check for presence of line numbers, variable names, or API calls from the input snippet. Manual spot-check on 10 random samples. |
Impact Statement Relevance | Impact description is specific to the code context (e.g., 'this deserialization path accepts user-controlled input') in >= 85% of cases. | Impact is a boilerplate severity description copied from the rule metadata with no contextualization. | Semantic similarity comparison between generated impact and rule's default impact string. Flag if cosine similarity > 0.8 without added context. |
Fix Guidance Actionability | Fix suggestion includes a concrete code change or refactoring direction that a developer could implement in >= 80% of cases. | Fix suggestion is 'remove the vulnerability' or 'follow secure coding practices' without a specific action. | Check for presence of code-level verbs (rename, wrap, validate, escape, parameterize). Manual review on 20 random samples for implementability. |
False Positive Boundary Handling | When [FINDING] is a known false positive pattern, explanation acknowledges the limitation and states why the rule still fired in >= 90% of cases. | Explanation treats all findings as true positives with no caveat, or confidently asserts a false positive without evidence. | Include 5 known false positive cases in golden dataset. Verify explanation contains caveat language or boundary acknowledgment. |
Developer Comprehension Score | A developer with 2+ years experience can understand the explanation and know what to fix within 60 seconds in >= 85% of cases. | Developer reports confusion, asks for clarification, or cannot identify the fix location after reading the explanation. | Timed comprehension test with 3 developers on 10 random samples. Measure time-to-understanding and fix identification accuracy. |
No Hallucinated Rule Logic | Explanation does not invent rule logic, detection mechanisms, or tool behavior not present in [RULE_DEFINITION] in 100% of cases. | Explanation claims the rule 'traces taint through 7 methods' or 'uses abstract interpretation' when rule definition provides no such detail. | Automated fact-checking against [RULE_DEFINITION] fields. Flag any claim about detection mechanism not present in rule source. |
Tone and Blame Avoidance | Explanation uses neutral, technical language without implying developer incompetence or negligence in 100% of cases. | Explanation includes phrases like 'the developer forgot', 'careless mistake', or 'obvious error'. | Sentiment and tone classifier check. Manual review of any explanation with negative sentiment score below threshold. |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Start with the base prompt and a single rule family (e.g., Semgrep security rules). Use a lightweight JSON schema with only rule_id, explanation, and fix_suggestion fields. Skip severity reclassification and policy mapping. Run against 10-20 findings from one scan and review manually.
Prompt modification
codeYou are a static analysis interpreter. Given a [RULE_DEFINITION] and [CODE_SNIPPET], explain why the rule fired in plain language. Return JSON with: - rule_id: string - explanation: string (2-4 sentences) - fix_suggestion: string (1-2 sentences)
Watch for
- Explanations that parrot the rule description without connecting to the code
- Missing context about what the code is supposed to do
- Overly technical explanations that junior developers won't understand

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us