14A.2 Review Standards, Coding and Prompt Conventions

Ship & get hiredLesson 2 of 106,441 words9 parts
Module 14A · 0 of 10 lessons done
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10

Code review is where a team's shared standards become real. For ordinary software the habits are well known: small pull requests, a second pair of eyes, tests that pass. LLM software adds new ways to be wrong. A one-line change to a prompt can shift behaviour across thousands of cases. A model name edited in a config file can change cost, quality and data handling in one commit. A reviewer reading the diff cannot see any of that: the diff looks tiny and harmless. This lesson teaches what a good review standard for LLM work contains: a code review checklist, a prompt review process, an eval-before-merge rule, tracing and cost conventions, naming and secrets rules, a pull-request template and a definition of done. You will learn how to apply it as an author and as a reviewer, and how to check that your team actually follows it. It is a template lesson: the general practice is written out in full, every fact that only your organization knows (your review turnaround, who approves, your branch rules, your tools) is marked as a placeholder, and the filled-in sample belongs to a fictional company, Northwind Analytics, and is clearly labelled as an example.

What you'll learn

  • Why LLM changes need review practices beyond normal code review
  • A reviewer's checklist for LLM code: model calls, timeouts and retries, output validation, tools, secrets, data and cost
  • How to review a prompt change: versioning, readable diffs, and eval evidence
  • The eval-before-merge rule, how change risk decides how much evidence is needed, and what counts as evidence
  • Conventions for tracing, cost attribution, naming, configuration and secrets
  • What goes in a pull-request template and a definition of done
  • How to be a good reviewer and a good author, and how to disagree productively
  • How to build and run a small PR-description linter, and how to design an eval set that tests whether your review standard works

What you don't need

  • API keys. The only code is a pure Python standard-library linter. It reads text; it never calls a model.
  • Docker or any local service.
  • A particular Git host. The conventions apply to any pull-request or merge-request workflow.

Setup

No installs. Python 3.11 or later and a text editor. This lesson is written "as of 1 December 2026". The tools and features named (tracing standards, CI services) change, so check their official pages when you adopt them.

bash
mkdir -p review_kit && cd review_kit
# save the script from Part 7 as pr_lint.py
python3 pr_lint.py

What you must be able to do after this lesson#

  • Explain why LLM changes need review beyond normal code review
  • Review LLM code using a checklist covering timeouts, retries, output validation, secrets and cost
  • Review a prompt change using its version, a readable diff and eval evidence
  • Apply the eval-before-merge rule and match the evidence required to the change risk
  • Write a pull-request description with what changed, evidence, rollback and a checklist

Why this matters for an AI engineer#

You will hear these phrases in review threads within your first month. Each one names a practice you can learn now.

You'll hear... You'll understand it after...
"Where's the eval run for this prompt change?" Part 4
"Please bump the prompt version." 3.1 Prompts are code
"That timeout is missing." 2.2 Timeouts, retries and budgets
"Did you validate the model output?" 2.3 Treat output as untrusted input
"Tag the span with the feature name and the cost centre." 5.2 Cost attribution
"No keys in the diff, ever." 6.3 Secrets
"Is that in the PR checklist?" Part 7
"Needs a second reviewer: it touches the system prompt." 8.2 Who reviews what

Part 1: Why LLM work needs its own review standard#

1.1 What is different about LLM changes#

In ordinary code, a reviewer reads the change and reasons about what it does. In LLM code, much of the behaviour is not in the diff.

Difference What it means for review
Behaviour lives in a prompt and a model. Changing either alters outputs without changing any control flow A diff of three words may be a high-risk change
Outputs are probabilistic. The same input can give different outputs "It worked when I tried it" is not evidence. You need a dataset and a score
Quality regresses silently. Nothing crashes when answers get worse Without an eval, nobody notices until users complain
Cost scales with text. A longer prompt, a bigger model or a retry loop changes spend Cost is a review concern, not only a finance concern
Data flows are easy to hide. A prompt can include customer text, and a trace can store it Reviewers must ask "what data is in this call, and where does it go?"
Tools give the model power. An agent can read, write and spend Permission changes are security changes (14A.3)

04.10 makes the same case for prompts ("a prompt is a production artefact"), and 11C.2 introduces change-risk classification: the idea that the amount of checking a change needs depends on its blast radius. A review standard turns those ideas into daily habits.

1.2 What a review standard should contain#

A short list, because standards nobody reads do nothing:

  1. A checklist for code review that is specific to LLM code.
  2. A process for prompt changes, including versioning and evidence.
  3. The eval-before-merge rule: which changes need an eval run, and what the run must show.
  4. Conventions for tracing, cost tags, naming, configuration and secrets.
  5. A pull-request template that asks for the things reviewers need.
  6. A definition of done that says when work is really finished.
  7. Roles and timing: who must approve which kinds of change, and how fast reviews happen.

Items 1 to 6 are general practice and this lesson teaches them. Item 7 is organization-specific.


Part 2: A code review checklist for LLM code#

Use this checklist as a reviewer. As an author, run through it before you ask anyone to look. Each item has a why so that you can apply the idea to cases the list does not mention.

2.1 Model calls#

  • Model identifier matches the registry. The string in code or config is a pinned snapshot that is in the approved registry (14A.1). Why: an unapproved or alias model silently changes data handling and behaviour.
  • Provider and region come from configuration, not from a hard-coded string in business logic. Why: the approved list changes, and portable code makes a change cheap (03.11).
  • Parameters are explicit where they matter (maximum output tokens, temperature or the equivalent, the reasoning setting if the model has one). Why: defaults differ between models and change over time.
  • Calls go through the shared client or wrapper, not a raw SDK call. Why: that is where timeouts, tracing, budgets and policy checks live.

2.2 Timeouts, retries and budgets#

  • Every call has a timeout. Why: a hung call holds a worker, a connection and a user.
  • Retries are bounded, use backoff, and apply only to retryable errors (03.8). Why: unbounded retries multiply cost during an outage.
  • There is a token or cost ceiling per request, per run, or per agent loop. Why: a loop without a ceiling is a bill without a ceiling.
  • Agent loops have a step limit and a defined stop condition (08A.2).
  • There is a fallback or a clear failure message for provider errors (11C.3).

2.3 Treat model output as untrusted input#

  • Structured output is validated against a schema before it is used (03.4). Why: models sometimes return malformed or unexpected structures.
  • Output is never executed or interpolated into a query, command or template without escaping. Why: model output can contain attacker-controlled text (12.2, 12.5).
  • Failure of validation has a defined path (retry once, fall back, or return an error), not a silent default.
  • Free text shown to users goes through whatever content checks the product requires.

2.4 Tools and agents#

  • Each tool has the least privilege it needs. Read-only where possible. Why: a prompt-injected agent can only misuse the permissions it has (12.6).
  • Tool inputs are validated like any other external input, because the model produces them.
  • Actions with side effects (sending, deleting, paying, writing) have an approval step or a clear reason they do not.
  • A new tool or a widened permission needs a second reviewer (see 8.2).

2.5 Data#

  • The data class of everything in the prompt is known, and the model is approved for that class (14A.1, 14A.3).
  • Personal data is minimised or redacted before it is sent or logged.
  • Test fixtures contain no real customer data. Use synthetic or scrubbed examples.
  • Logging does not store raw prompts for sensitive classes unless the policy allows it.

2.6 Cost and performance#

  • Estimated cost is stated for any change that increases prompt size, adds calls, or switches models (11B.1, 11B.2).
  • Stable prefixes are kept stable where caching is used, because reordering a prompt can destroy a cache hit rate (11B.4).
  • Latency impact is considered for user-facing paths, especially added sequential calls.

2.7 General quality#

  • Tests exist and are deterministic where possible (fakes and recorded responses, not live calls in unit tests: 03.10).
  • Errors are logged with enough context to debug, without leaking data.
  • The change is small enough to review. If a pull request mixes a model upgrade, a prompt rewrite and a refactor, ask the author to split it. Why: when quality changes, you need to know which change caused it.

Part 3: Reviewing prompts#

3.1 Prompts are code#

A prompt is source code that is executed by a model. It deserves the same discipline: it lives in version control (not in a chat window or a database nobody can diff), it has a version, it is reviewed, it is tested and it can be rolled back. 04.10 Part 4 covers the mechanics of versions (semantic versions or content hashes), pinning and aliases, and treating a prompt and model as one unit: a prompt tuned for one model is not guaranteed to behave the same on another.

A prompt standard usually requires:

  • one file per prompt, in a known directory, with metadata (name, version, owner, the model it was evaluated on);
  • a version bump on every behavioural change;
  • a changelog line saying what changed and why;
  • a link to the eval run that supports the change.

3.2 Making prompt diffs reviewable#

Plain-text diffs of prompts are noisy if the prompt is one long line. Two habits make them readable. First, put one instruction per line (or per bullet) so a changed rule shows as a changed line. Second, separate the template (instructions and structure) from the data (variables and examples), so reviewers see which part changed.

A good prompt review asks:

Question Why
What behaviour is this change meant to produce, in one sentence? Without intent, nobody can judge success
Which rule was added, removed or reworded? A reworded rule can change meaning
Could the change weaken a safety or format rule? Removing "never reveal..." lines is a security change
Do new variables carry untrusted text? User text inside instructions invites injection (12.2)
What do the evals say, on which cases, against which baseline? Opinion is not evidence
What happens on rollback? The previous version must still work

3.3 A worked example: reviewing a small prompt diff#

Suppose an author opens a pull request titled "Make refund answers friendlier". The diff:

diff
 You are a support assistant for Northwind Analytics.
-Answer in two sentences. Quote the refund policy section by name.
+Answer warmly. Keep it short. Mention the policy if relevant.
 Never promise a refund; say that the support team will confirm.

The reviewer's thought process, step by step:

  1. Intent: friendlier tone. Reasonable.
  2. What changed: three rules were reworded. "Two sentences" became "keep it short" (vague). "Quote the policy section by name" became "mention the policy if relevant" (weaker, and optional now).
  3. Risk: the citation rule was probably there so answers could be checked against the policy. Making it optional could reduce faithfulness. The "never promise" line is unchanged, which is good.
  4. Evidence: the pull request has no eval run. The reviewer cannot tell whether tone improved or whether citations dropped.
  5. Decision: request changes. Ask for an eval run on the refund-question set, with metrics for tone and for citation presence, compared with the baseline, and keep the citation rule unless the numbers justify removing it.

This is the pattern in miniature: find what the diff weakens, ask for the evidence, and require a baseline comparison.

3.4 The prompt-change checklist#

For every prompt pull request:

  1. The prompt file version is bumped, and the changelog line is present.
  2. The model the prompt was evaluated on is named (and is in the registry).
  3. An eval run id or link and a baseline id or link are attached (Part 4).
  4. Safety and format rules are unchanged, or the change is called out explicitly.
  5. New variables are marked as trusted or untrusted.
  6. The rollback step is written down.

11C.2 Part 5 gives a longer prompt-change PR template to copy from.


Part 4: The eval-before-merge rule#

4.1 The rule#

A change that can alter model behaviour does not merge until an eval run shows it is not worse than the baseline on the agreed metrics.

"Can alter model behaviour" includes prompt edits, model or parameter changes, retrieval changes (chunking, embeddings, rerankers), tool descriptions, and changes to guardrails or output parsers. It does not include a typo fix in a comment. Teams that skip the second half of the rule ("not worse than the baseline") end up merging changes on the strength of a few examples someone tried by hand.

4.2 Change risk decides how much evidence#

Not every change needs the biggest suite. 11C.2 §1.4 classifies changes by risk. A review standard can adopt a simple three-level version:

EXAMPLE ONLY (fictional company, Northwind Analytics). Real tiers and thresholds differ per organization.

Risk Examples Evidence required
Low Comment, logging text, test-only change Normal tests pass
Medium Prompt wording change, parameter change, new few-shot example Fast eval suite on the affected feature, compared with baseline
High Model change, new tool or wider permission, retrieval pipeline change, system-prompt safety rules Full eval suite plus safety cases, a cost estimate and a second reviewer

4.3 What counts as evidence#

Good evidence has five properties:

  1. A named dataset with a version, so the run is repeatable (10A.2).
  2. Defined metrics with a pass rule decided before the run (10A.3, 10A.4).
  3. A baseline: the same suite run on the current production version.
  4. A comparison that accounts for noise. If outputs vary, run enough cases or repeats to tell a real change from chance (10A.8 Part 2).
  5. A link in the pull request to the stored result, so a reviewer can open it.

"I tried five examples and it looked good" fails properties 1, 2, 3 and 4. It is a demo, not evidence.

4.4 Make it automatic#

The cheapest way to apply the rule is to let CI do it: a job runs the suite on pull requests that touch prompts, models or retrieval code and posts the comparison. 10A.8 and 11C.2 cover gates, tiered suites and CI mechanics. A human reviewer then checks that the suite itself is adequate for the change, and that the suite was not weakened in the same pull request (a classic way to make a failing run pass).


Part 5: Tracing, cost and logging conventions#

Deep-dive

5.1 Why conventions matter more than tools#

Every team can pick a tracing tool. What makes traces useful is that everyone names things the same way. Without conventions, one team's span is called llm_call, another's chat.completion and a third's generate, and nobody can build a dashboard that spans services. The minimum set of conventions:

Convention Example (fictional) Why
Span names llm.chat, llm.embed, tool.<name>, retrieval.search Dashboards and alerts can filter by name
Required attributes feature name, prompt name and version, model id, provider, region, environment Lets you slice quality and cost by what changed
Token attributes input tokens, output tokens, cached tokens Enables cost and cache analysis
Error attributes error class, retry count, final outcome Makes reliability measurable
Correlation id one request id passed through every call Lets you follow a user request across services
Sampling rule how many traces are kept, and whether errors are always kept Controls cost and storage

03.12 shows a minimal tracing wrapper, 11A.1 covers tracing and observability in production, and 11A.1, sections 3.7 and 3.8 cover the open standard for attribute names. The OpenTelemetry GenAI semantic conventions are the standard to adopt when your team chooses names, instead of inventing your own.

5.2 Cost attribution#

Cost that nobody owns grows. A standard should require every model call to carry tags that say who pays and why:

  • the feature or product name,
  • the team or cost centre,
  • the environment (development, staging, production),
  • the model identifier (already on the span).

With those four tags you can answer "which feature costs the most?", "which team is over budget?" and "did the new prompt make this feature more expensive?" (11B.2 shows how to calculate cost per request and per feature). The pull-request template should ask for a cost note whenever a change affects prompt size, call count or model choice.

5.3 What not to log#

Conventions also say what stays out of traces: secrets, raw personal data, and (for sensitive data classes) raw prompts and completions. The common compromise is to log metadata always and content sometimes: full content in development, redacted or sampled content in staging, and metadata only for sensitive data in production. 14A.3 states the retention and logging rules in detail, and 12.4 explains why your own logs are a leak point.


Part 6: Naming, layout, configuration and secrets#

Deep-dive

6.1 Naming#

Boring, predictable names are a feature. A typical standard fixes:

  • Prompt files: prompts/<feature>/<name>.prompt.md, with the version in metadata.
  • Model identifiers: only the exact pinned string from the registry; never an abbreviation in code.
  • Eval datasets and runs: <feature>-<purpose>-v<N> for datasets and a date-plus-id for runs.
  • Config keys: llm.<feature>.model, llm.<feature>.max_output_tokens.
  • Branches and commits: a prefix for the type of change, such as prompt:, model:, eval:, fix:. A type prefix lets reviewers and CI route a change to the right checks.

6.2 Configuration over constants#

Anything that changes without a code change belongs in configuration: model id, provider, region, parameters, thresholds, feature flags. Anything that reviewers must look at belongs in a file that appears in the diff. That is why a model change should be one line in one config file, clearly labelled, and not a string buried in a helper function.

6.3 Secrets#

The rules are short and absolute:

  1. No secrets in the repository, ever: not in code, tests, notebooks, config examples or prompt files.
  2. Keys come from a secrets manager or environment variables injected at runtime.
  3. Example files use obvious placeholders.
  4. A secret scanner runs in CI and pre-commit.
  5. A committed secret is treated as leaked: it is revoked and rotated immediately, even if the commit is removed from history. Deleting the line does not un-leak the key.
  6. Different keys for development, staging and production, and per-service keys where possible, so one leak has a small blast radius.

12.10 covers secure coding and CI security controls, and 14A.3 has the policy side.


Part 7: Pull-request templates, definition of done and a linter you can run#

7.1 The pull-request template#

A template turns a standard into a form. The goal is to make the author supply what the reviewer would otherwise have to ask for. A good LLM template has five parts: Summary (why), What changed (which prompts, models, configs, code), Evidence (eval run, baseline, cost note), Rollback (how to undo), and a Checklist of the rules above.

EXAMPLE ONLY (fictional company, Northwind Analytics). The wording is invented.

markdown
## Summary
<one or two sentences: what problem does this solve?>

## What changed
<prompts, model ids, config keys, tools, code>

## Evidence
Eval run: <id or link>
Baseline: <id or link>
Cost note: <expected change in cost per request, or "none">

## Rollback
<how to undo this change quickly>

## Checklist
- [ ] No secrets, keys or customer data in the diff
- [ ] Model and region are on the approved list
- [ ] Eval run attached for any prompt or model change
- [ ] Trace names and cost tags follow the conventions
- [ ] Rollback step is written down

7.2 A definition of done#

"Done" should mean more than "merged". A definition of done for an LLM feature typically includes:

  1. The code is reviewed and merged under the rules above.
  2. Evals exist for the feature, pass in CI and are part of the regression suite.
  3. Tracing and cost tags are in place and visible on a dashboard.
  4. The model and region are on the approved list, and retirement dates are recorded.
  5. Data handling is documented (classes involved, redaction, retention).
  6. Alerts and a rollback or kill switch exist for production features.
  7. A short runbook says what to do when quality, cost or availability degrades.
  8. The prompt and eval datasets have owners.

7.3 Try it: a PR-description linter#

Reviewers should spend their attention on judgement, not on noticing that a template section is empty. A tiny linter can check the mechanical parts: required sections present, checklist ticked, and (for prompt or model changes) an eval run and a baseline mentioned. The script below does exactly that. It uses only the standard library, reads a pull-request body and a list of changed file paths, and its rules and sample text are a fictional example.

python
"""pr_lint.py: lint a pull-request description against an LLM-change checklist.
Standard library only. Rules and wording are a FICTIONAL example."""
from __future__ import annotations
import re
import sys

REQUIRED_SECTIONS = ["Summary", "What changed", "Evidence", "Rollback", "Checklist"]
PROMPT_PATHS = re.compile(r"^(prompts/|.*\.prompt\.(md|yaml)$)")
MODEL_PATHS = re.compile(r"(models?\.(yaml|toml|json)$|llm_config)")
CHECKLIST_ITEMS = [
    "No secrets, keys or customer data in the diff",
    "Model and region are on the approved list",
    "Eval run attached for any prompt or model change",
    "Trace names and cost tags follow the conventions",
    "Rollback step is written down",
]


def lint(body: str, changed_files: list[str]) -> list[str]:
    problems = []
    headings = {m.group(1).strip() for m in re.finditer(r"^##\s+(.+)$", body, re.M)}
    for s in REQUIRED_SECTIONS:
        if s not in headings:
            problems.append(f"missing section: ## {s}")
    for item in CHECKLIST_ITEMS:
        box = re.search(r"- \[(x| )\] " + re.escape(item), body)
        if not box:
            problems.append(f"checklist item absent: {item!r}")
        elif box.group(1) == " ":
            problems.append(f"checklist item not ticked: {item!r}")
    touches_prompt = any(PROMPT_PATHS.match(f) for f in changed_files)
    touches_model = any(MODEL_PATHS.search(f) for f in changed_files)
    if touches_prompt or touches_model:
        if not re.search(r"eval[- ]run:\s*\S+", body, re.I):
            problems.append("prompt or model change without an 'Eval run: <id or link>' line")
        if not re.search(r"baseline:\s*\S+", body, re.I):
            problems.append("prompt or model change without a 'Baseline: <id or link>' line")
    if touches_model and not re.search(r"registry|approved list", body, re.I):
        problems.append("model change does not mention the registry or approved list")
    return problems


GOOD = """## Summary
Tighten the refund-policy prompt.
## What changed
prompts/refund_policy.prompt.md v1.4.0 to v1.5.0
## Evidence
Eval run: run-2026-11-30-a
Baseline: run-2026-11-27-b
## Rollback
Pin prompt alias back to v1.4.0.
## Checklist
- [x] No secrets, keys or customer data in the diff
- [x] Model and region are on the approved list
- [x] Eval run attached for any prompt or model change
- [x] Trace names and cost tags follow the conventions
- [x] Rollback step is written down
"""

BAD = """## Summary
Switch to the new model, should be fine.
## What changed
config/models.yaml
## Checklist
- [x] No secrets, keys or customer data in the diff
- [ ] Eval run attached for any prompt or model change
"""

if __name__ == "__main__":
    for name, body, files in [("GOOD", GOOD, ["prompts/refund_policy.prompt.md"]),
                              ("BAD", BAD, ["config/models.yaml"])]:
        problems = lint(body, files)
        print(f"{name}: {'PASS' if not problems else 'FAIL'}")
        for p in problems:
            print("   -", p)
    sys.exit(0)

Run it:

bash
python3 pr_lint.py

Real output:

text
GOOD: PASS
BAD: FAIL
   - missing section: ## Evidence
   - missing section: ## Rollback
   - checklist item absent: 'Model and region are on the approved list'
   - checklist item not ticked: 'Eval run attached for any prompt or model change'
   - checklist item absent: 'Trace names and cost tags follow the conventions'
   - checklist item absent: 'Rollback step is written down'
   - prompt or model change without an 'Eval run: <id or link>' line
   - prompt or model change without a 'Baseline: <id or link>' line
   - model change does not mention the registry or approved list

What the linter does and does not do:

  • It enforces form: the right sections exist, the boxes are ticked, the evidence lines are present when a prompt or model file changed.
  • It cannot judge substance: a PR can say Eval run: none and pass the pattern. The human reviewer opens the link and checks that the run is real and the numbers are good. A linter removes the dull checks so the human can do the hard one.
  • It routes by file path: the regular expressions at the top decide what counts as a prompt file or a model file. Your repository layout decides those patterns, which is why naming conventions (6.1) and linters go together.

Part 8: Being a good reviewer and a good author#

Deep-dive

8.1 Author habits#

  • Keep changes small and single-purpose. One concern per pull request makes both review and rollback easier.
  • Say what you want checked. "I am unsure about the retry limit" directs attention.
  • Show the evidence in the description, not only in a link nobody opens. A two-line table of before and after scores helps.
  • Do not argue with the evidence. If the eval shows a regression, fix the change or explain why the metric is wrong in a separate, reviewed change.

8.2 Who reviews what#

A standard names which changes need which reviewers. A typical pattern: any engineer can review low-risk changes; medium-risk changes need a reviewer who owns the feature; high-risk changes (model changes, new tools, permission changes, safety-rule edits, retrieval pipeline changes) need a second reviewer from outside the team or from the security or AI platform group.

8.3 Reviewer habits#

  • Review the risk, not the style. Formatters and linters handle style. Your time goes to behaviour, data, cost and safety.
  • Ask for evidence rather than assert opinions. "Which cases cover this rule?" is better than "I think this will break."
  • Be specific. Point at the line and say what you expect.
  • Separate blocking from non-blocking comments. Label suggestions as optional.
  • Respond quickly. Slow reviews lead to large pull requests, which are harder to review, which makes reviews slower still.

8.4 Disagreement and escalation#

Sometimes author and reviewer cannot agree. Good standards give a tie-break path: a named technical owner for the area decides, and the decision is recorded in the pull request. The aim is not to win, but to avoid a pull request stuck for weeks and to leave a record that explains the decision to the next engineer.

8.5 Reviewing AI-assisted code#

Engineers increasingly write code with AI assistants, and that raises a standard question: who is responsible for generated code? The usual answer is simple: the author who opens the pull request owns every line in it, however it was produced. Reviewers apply the same checklist. Extra care is warranted for code that calls models, because assistants may suggest outdated model names, deprecated parameters or insecure patterns. Always check generated model identifiers against the registry and the provider's current documentation.


Part 9: Evaluate it: does your review standard work?#

Deep-dive

A standard is a hypothesis: "if engineers follow this, bad changes get caught." You can test that hypothesis with a small eval set, in the same spirit as your product evals. This part designs a tiny one. It builds on 10A.2 (building datasets), 10A.3 (deterministic checks), 10A.4 (model-graded checks) and 10A.8 (regression gates).

9.1 Three things to test#

  1. The linter is correct (deterministic code, so exact expectations).
  2. The gate catches bad changes (a set of known-bad pull requests that must be blocked).
  3. If you use an AI review assistant, it flags the right problems (model-graded, with a hard-fail rule for the worst misses).

9.2 The dataset#

Build a list of seeded pull requests. Each entry is a small description plus a list of changed files, labelled with the defects it contains. Seed one defect per case, plus clean cases:

Case Seeded defect Expected
clean-prompt None: sections complete, eval and baseline present PASS
missing-eval Prompt file changed, no eval run line FAIL with eval message
missing-baseline Eval run present, no baseline FAIL with baseline message
unticked-box One checklist item unticked FAIL with item message
model-no-registry Model config changed, no mention of the registry FAIL with registry message
eval-weakened Threshold lowered in the same PR as a prompt change Flag for human review (the linter alone cannot decide)
secret-in-diff A key-shaped string in the changed text Block (use a secret scanner, not the linter)
tool-added New tool added without a second reviewer Needs second reviewer

Keep the set at roughly twenty to forty cases, store it next to the linter, and add a case every time a real defect escapes review. That last habit is the one that makes the set valuable: every escaped defect becomes a permanent test.

9.3 Metrics and pass rules#

What Metric Pass rule
Linter correctness decision and message match expected, per case 100 percent (deterministic code)
Gate effectiveness share of seeded bad PRs that are blocked or flagged 100 percent of the seeded set; track the miss rate on real escapes over time
False alarms share of clean cases wrongly blocked 0 percent on the clean cases
Review assistant (optional) recall on seeded defects, scored by a judge with a rubric recall at or above a threshold you set, and a hard fail on any missed secret or missed unapproved model
Review time (a process metric, not an eval) time from request to first review tracked against your service-level expectation

For the optional model-graded check, remember that a judge is itself a model and needs calibration (10A.5).

9.4 Tools#

You do not need a framework for the deterministic parts: a list of cases and a loop with assertions is enough. When you add model-graded review or want datasets, custom metrics and CI gates in one place, use the DeepEval lessons (10B.2, 10B.3, 10B.4, 10B.5, 10B.6 and 10B.7). To see the same design in a second framework, the optional Inspect lessons (10B.8 (optional), 10B.9 (optional), 10B.10 (optional), 10B.11 (optional)) show datasets, scorers and model grading, and 10B.17 (optional) helps you choose. For agent behaviour under review, see 10A.7.


Common misconceptions#

  • "A small diff is a low-risk diff." In LLM code, three words in a prompt or one line in a model config can change behaviour everywhere.
  • "I tried it on a few examples and it looked fine." That is a demo. Evidence needs a dataset, a metric, a baseline and a link.
  • "The linter passed, so the PR is good." Linters check form. A human still has to open the evidence and judge it.
  • "Reviewers should catch everything." Humans are bad at noticing missing things. Automate the mechanical checks and keep people for judgement.
  • "Lower the threshold so CI goes green." Changing the bar in the same change as the behaviour makes the evidence meaningless.
  • "Generated code is the assistant's responsibility." The author who opens the pull request owns it.
  • "Deleting a leaked key from the commit fixes it." The key must be revoked and rotated. History and clones may still hold it.

Key takeaways#

  1. LLM changes hide behaviour in prompts and models, so review must look beyond the diff.
  2. A review standard has seven parts: code checklist, prompt process, eval-before-merge, conventions, PR template, definition of done, and roles and timing.
  3. Five questions cover most reviews: approved, bounded, output checked, data safe, evidence attached.
  4. Review prompts like code: version them, diff them readably, and demand an eval run against a baseline.
  5. Match evidence to risk: low-risk changes need tests, high-risk changes need the full suite, safety cases, a cost estimate and a second reviewer.
  6. Conventions for span names, attributes, cost tags and secrets matter more than the choice of tool.
  7. Automate mechanical checks (linters, scanners, policy checks) so that humans spend attention on judgement.
  8. Every escaped defect becomes a permanent test case.

Terms introduced in this lesson#

Term Meaning
Review standard A written set of checks, conventions and roles that govern how changes are reviewed
Eval-before-merge rule The rule that behaviour-changing work merges only after an eval run shows no regression against a baseline
Change risk tier A classification (low, medium, high) that sets how much evidence a change needs
Baseline The eval results of the current production version, used for comparison
Pull-request template A form that asks the author for summary, changes, evidence, rollback and a checklist
Definition of done The list of conditions that must hold before work counts as finished
Span attribute A named piece of metadata attached to a trace span (model id, prompt version, tokens)
Cost tag A label on a call that says which feature, team and environment pays for it
Seeded pull request A test pull request with a known, planted defect used to check that the review process catches it
Secret rotation Replacing a credential with a new one and revoking the old one

Exercises#

  1. Review a diff. Take the refund-prompt diff in 3.3 and write your full review comment, including the evidence you would ask for and the metrics you would choose. Hint: name the baseline, the dataset and a pass rule before you comment.
  2. Adapt the template. Take the PR template in 7.1 and add two fields your team would need (for example a data-class line and a kill-switch line). Update the linter to require them. Hint: add the section names to REQUIRED_SECTIONS and write a case that must fail without them.
  3. Extend the linter. Add a rule that fails a PR if the changed files include a prompt file but the file's version line did not change. Hint: pass the old and new text of the file, or the diff, into the function.
  4. Seed a defect set. Write ten seeded pull requests (descriptions plus file lists) with one defect each, plus three clean ones. Run the linter over them and compute the miss rate. Hint: include at least one defect the linter cannot catch and say which tool or person should.
  5. Define span conventions. Write your own tracing convention table (span names, required attributes, sampling) for one feature. Hint: check 03.12 for a minimal set, then add cost tags.
  6. Write a definition of done. Write an eight-line definition of done for a new AI feature, and mark which lines can be automated. Hint: aim to automate at least half.

Check yourself#

  1. Give three reasons why a three-word prompt change can be high risk.
  2. List the five questions that cover most LLM code reviews.
  3. Why should model identifiers come from configuration and match the registry?
  4. What five properties make eval evidence good?
  5. Why should an eval change and a behaviour change not land in the same pull request?
  6. What does a PR linter enforce, and what can it not judge?
  7. Name four attributes every model-call span should carry.
  8. What must you do if a key is committed to the repository?
  9. Who owns AI-generated code in a pull request?
  10. What should you do each time a defect escapes review?

Further resources#


← 14A.1 — Approved Providers, Models and Regions | Module 14A overview | 14A.3 — Security, Data and Compliance Policy →

Esc
02.2Tokens and TokenizationHow LLMs Work · 21k wordsLesson
02.3EmbeddingsHow LLMs Work · 18k wordsLesson
07Retrieval-Augmented Generation (RAG)11 lessons · Everyone who will build LLM features that must answer from knowledge the model doesn't have in its weights: internal handbooks and help centres, contracts, ticket histories, product docs, or any corpus that changes faster than a training run. The module covers the full RAG stack — architecture, retrieval strategy, query understanding, grounded generation, citations, conversation, managed services, advanced patterns, evaluation, debugging and production operation — and shows where each major provider's managed retrieval and citation features fit (OpenAI, Anthropic, Google Gemini and OpenRouter). All code is Python.Overview
08E.1The Model Context Protocol (MCP)Protocols and Extensibility · 12k wordsLesson
↑ ↓ navigate↵ openesc close