Skip to content

Show the borderline cases with examples

Choose and write two to four targeted few-shot examples that make a CI reviewer consistent on ambiguous cases, showing the reasoning, the output format and acceptable patterns versus real issues.

Scenario

Scenario: Claude Code for Continuous Integration. Your SaaS product keeps every customer's data in shared tables, so every query must be scoped to the caller's tenant. The CI reviewer checks for that, and on clear cases it's right.

On the borderline ones it flips. The same cross-tenant read in the nightly billing job was flagged "high" on Monday and ignored on Wednesday. Some findings come with a fix, some with "consider reviewing". The prompt already has three paragraphs of rules about tenant scoping. A fourth paragraph won't help.

Explanation

When rules give inconsistent output, show examples. Anthropic's prompting guide calls examples one of the most reliable ways to steer Claude's output format, tone and structure. A few well-chosen examples (few-shot or multishot prompting) improve accuracy and consistency where detailed instructions alone don't.

Target the ambiguous cases. Claude already handles the clear ones. Spend your examples on the borderline cases where it flips, and keep the set small. The exam guide speaks of two to four targeted examples for the ambiguous cases; Anthropic's prompting guide suggests 3–5 examples for best results. Either way, each example should show:

  1. The input: the code, with its location.
  2. The decision: report, skip, or ask the author.
  3. The reasoning, as a short justification: why this decision and not the plausible alternative, in a sentence or two. This is what lets Claude apply the same judgement to code your examples never showed. Label it as a justification ("Why:"), not a fixed "Reasoning:" field to fill in: current docs list reasoning asked for in a fixed format as a common cause of refusals on newer models.
  4. The exact output format: location, issue, severity, suggested fix. Claude copies the shape it sees.

Include acceptable patterns as well as real issues. An example that says "this looks wrong but is fine here, because…" removes a class of false positives. One set that holds both sides teaches where the line is, so Claude generalizes instead of matching only the cases you listed.

Keep examples apart from instructions. Wrap each one in <example> tags inside an <examples> block, and vary them enough that Claude doesn't pick up an accidental pattern, such as every example coming from the same folder.

The same technique works for extraction: examples of documents with different layouts help Claude find a field it would otherwise return empty.

Worked example

Three tenant-scoping cases flip. Instead of a fourth rules paragraph, the prompt gets three examples. Two of them:

<example>
Code: src/jobs/nightly-billing.ts:42 db.invoice.findMany({ where: { status: "open" } })
Decision: skip
Why: this nightly job runs as the system and must read every tenant's open invoices. Cross-tenant reads in src/jobs/ are intended. The same query in a request handler would be a finding.
</example>
<example>
Code: src/api/projects.ts:88 db.project.findUnique({ where: { id: req.params.id } })
Decision: report
Location: src/api/projects.ts:88
Issue: the project is looked up by an id from the URL with no tenant check, so any signed-in user can read another tenant's project by changing the id.
Severity: high
Suggested fix: db.project.findFirst({ where: { id: req.params.id, tenantId: ctx.tenantId } })
</example>

The third shows a helper in src/db/ that takes tenantId as a parameter and passes it on: skip, because the caller supplies the scope.

What each one adds: the job example draws the line between a system task and a request, the handler example fixes the output format and shows what an actionable fix looks like, and the helper example stops findings on code that is scoped one level up.