Skip to main content
Ai promptsLint policyCode styleClaude prompts

A Lint and Format Policy Prompt That Tames AI-Generated Code

A lint and format policy prompt that turns your style guide into an enforceable policy and a per-file violation report. Copy the prompt and output contract.

PPromptsCart Team·August 2, 2026·Updated August 2, 2026·7 min read

AI writes a lot of the code now, and it writes it in whatever style its training data favored. Snake_case sneaks into a camelCase project. A bare print() lands where your logger should be. Import order scrambles. CodeRabbit's own measurements put formatting problems at 2.66x more frequent and readability issues 3x worse in AI-generated code than in human-written code. The agent never read your style guide. It couldn't.

A lint and format policy prompt closes that loop two ways: it turns your loose style preferences into a written, enforceable policy, then checks code against that policy and reports violations by file and line. Not as a replacement for ESLint or Prettier, those run in CI and catch the mechanical stuff in milliseconds, but as the semantic layer above them.

Here's the prompt, the policy contract, and why the deterministic-only approach others recommend leaves a gap.

Why deterministic linting alone isn't enough for AI code

The smart writing on this argues for catching AI's predictable mistakes with deterministic rules. The widely shared Lint Against the Machine field guide lays out ten anti-pattern categories (duplication, bare excepts, any types, debugging residue, deprecated APIs) and the linter rule codes that catch them. It's right that "systematic problems yield to systematic prevention." But it explicitly stops at deterministic rules, and it's a concept guide, not a prompt.

That leaves two things uncovered. First, writing the policy: most teams have style opinions but no document, so there's nothing for a linter or a reviewer to enforce. Second, the semantic layer: a variable named data2, a function that follows the letter of the style guide but not its intent, a pattern that doesn't match the rest of the codebase. No regex catches "this name is bad." A prompt can.

Use cases like style guide enforcement workflows describe the goal but not a copyable method. This post is the method.

What you can do with this prompt

  • Turn scattered style preferences into a single written policy document.
  • Generate a starter linter config that encodes the deterministic half of the policy.
  • Check a diff or file against the policy and get violations by line, with fixes.
  • Catch semantic style issues linters miss: weak names, inconsistent patterns, logger misuse.
  • Hand AI agents the policy as context so they generate compliant code in the first place.
  • Onboard a new contributor with the policy instead of a tribal-knowledge code review.

Anatomy of the prompt

Two modes share one contract. Mode one writes the policy. Mode two enforces it. The output contract keeps both consistent.

Role:    You are a code style reviewer enforcing {{style_policy}}.
Context: {{style_policy}} — the team's written rules (or examples to infer from).
         {{code}} — the file or diff under review.
Task:    Check the code against the policy. For each violation, name the rule,
         the line, the severity (blocking vs advisory), and the corrected code.
         Skip anything a formatter (Prettier/Black) auto-fixes — call those out
         once, collectively, not line by line.
Output:  A table — File:Line | Rule | Severity | Current | Corrected.
         End with the policy gaps the code revealed (rules worth adding).
Write the policy from your code, not from scratch

Don't draft a style guide in the abstract. Paste three files you consider exemplary and ask the prompt to infer the policy they follow. The rules it extracts are the ones your team already lives by, which means they'll actually stick. A policy invented in a vacuum gets ignored by the second sprint.

Step-by-step usage

1. Gather inputs

For policy authoring, collect 3 to 5 files you'd hold up as the standard. For enforcement, grab the diff or file under review plus the policy you've already written.

2. Fill variables

Set {{style_policy}} and {{code}}. In authoring mode, leave the policy as "infer from these examples." In enforcement mode, paste the real policy.

3. Run the prompt

In enforcement mode, read the blocking violations first. Advisory ones (a slightly awkward name) are suggestions; blocking ones (wrong casing convention, banned pattern) gate the merge.

4. Post-process

Apply the corrections. For the "policy gaps" section, decide which suggested rules to adopt; that section is how the policy grows from real code over time.

5. Iterate

Feed the written policy back to your AI coding agent as a system instruction so it generates compliant code, shifting enforcement left from review to authoring.

Prompt-craft patterns

Separate blocking from advisory. A policy where everything is mandatory gets ignored because nobody can ship. Mark the casing and banned-pattern rules blocking; mark naming-quality suggestions advisory. The contract should carry the distinction.

Severity:
  blocking  = casing convention, banned API, security pattern
  advisory  = name could be clearer, comment would help, minor structure

Don't re-report what the formatter fixes. Prettier and Black handle whitespace and quotes deterministically. Tell the prompt to mention those once, collectively, and spend its attention on the semantic layer. Otherwise you drown real issues in indentation nags.

Give the policy to the agent, not just the reviewer. The highest-leverage use is prevention: paste the policy into your coding agent's context so it writes compliant code, the way you'd hand a well-written rules file to Cursor. Enforcement at review time is cleanup; enforcement at authoring time is the fix.

The opinionated take: stop reviewing formatting in pull requests entirely. If a human is leaving comments about quote style or import order, your tooling has failed, not your teammate. Push every deterministic rule into Prettier, Black, or ESLint on a pre-commit hook, and reserve human and LLM attention for the semantic layer this prompt targets, naming, patterns, and intent. Formatting debates in review are a tax on everyone's time and they never change anyone's mind.

Variables you'll set

VariableRequiredWhat it is
{{style_policy}}YesThe written policy, or example files to infer it from
{{code}}YesThe file or diff under review
{{language}}NoSets language-specific conventions and formatter
{{severity_rules}}NoYour blocking-vs-advisory definitions
{{formatter}}NoPrettier, Black, gofmt, so the prompt skips its territory

Getting started

  1. Pick 3 to 5 files that represent your standard.
  2. Run the prompt in authoring mode to extract the policy.
  3. Mark each rule blocking or advisory.
  4. Push deterministic rules into your formatter and linter config.
  5. Run enforcement mode on diffs for the semantic layer.
  6. Feed the policy to your AI agent so it generates compliant code.
  7. To make this a standing review gate, the Code Review Policy System Prompt includes maintainability and consistency as mandatory dimensions.
Browse the code quality prompt packs
Skip the setup

The Code Review Policy System Prompt turns style enforcement into a system prompt your reviews run every time: it defines the mandatory dimensions (correctness, security, performance, maintainability, test coverage) so consistency isn't left to whoever's reviewing that day. It's part of The Complete AI Prompts Bundle, a one-time lifetime license to the whole catalog plus every future pack, worth it once style is a team standard rather than a personal crusade.

Get the Code Review Policy System Prompt

A style policy is most powerful when it shapes code before review. Two reads on shifting it left: writing a .cursorrules file that actually works and writing an AGENTS.md file with AI, both of which hand your agent the conventions up front. For the semantic smells that slip past style rules, the Legacy Code Comprehension Harness reads what the code really does so your policy targets behavior, not just surface.

Read the code first with the Legacy Code Comprehension Harness
FAQ

Common questions

What is a lint and format policy prompt?
A lint and format policy prompt turns your team's style preferences into a written, enforceable policy and then checks code against it, reporting violations by file and line with a fix. It complements deterministic linters by catching the semantic style issues (naming quality, pattern adherence) that a regex can't.
Why does AI-generated code break style guides?
AI agents don't read your style guide; they generate from whatever patterns dominated training data. That means camelCase in a snake_case project, inconsistent import ordering, or print() instead of your logger. A policy prompt restates the rules in-context and flags the drift before it merges.
Can a prompt replace ESLint or Prettier?
No, and it shouldn't try. Deterministic linters catch mechanical issues in milliseconds and belong in CI. The prompt handles the layer above: semantic naming, pattern adherence, and writing the policy your linter config can't express in rules. Run the linter first, the prompt second.
Stop reading. Start shipping.

Get the prompt packs this guide is built on

Ready-to-paste prompts with documented variables and usage guides for ChatGPT, Claude, and Gemini. One-time payment, own it forever.