Dev.to · 9 min read

Lint Your AI Feature PRD Like Code: A Python Spec Checker for LLM Features

Lint Your AI Feature PRD Like Code: A Python Spec Checker for LLM Features

A normal spec works because the software is deterministic. Someone writes "add an export button," you build the button, and it does the same thing every time. An LLM feature breaks that. The same input can produce different outputs, "correct" is sometimes a judgment call, and the feature can fail confidently, slowly, or expensively. So the PRD for an AI feature needs a few extra sections, and some familiar ones need much sharper answers. If you're the engineer or tech lead who has to build from that document, you've probably had the review where the behavior section says "summaries should be accurate and concise" and nobody can say how you'd test it. This post walks through what a reviewable AI spec contains, from your side of the table, and then gives you about 190 lines of standard-library Python that lints a Markdown PRD for the gaps reviewers usually find late. About the numbers: every threshold, target, table row, and the whole sample spec below are made-up example data for a fictional ticket-summarizer feature. They're picked to make the checks easy to follow, not taken from any real product. Replace them with your own before you trust a READY verdict. Why lint a spec at all? Most teams already lint code, configs, and commit messages. The spec is often the one artifact that decides what gets built, and nothing checks it. For deterministic features, a reviewer's eyeball is usually enough. For LLM features, the omissions are expensive: a behavior with no test becomes a quality argument after launch, a failure mode with no owner becomes an incident nobody is paged for, and a rollout stage with no exit criteria becomes "let's just go to 100%." A linter won't tell you whether the spec is good. It tells you whether the spec is complete enough to argue about. That's the bar a review meeting needs. Keep the PRD as SPEC.md next to the feature code, run the linter in CI, and the review can spend its time on judgment calls instead of finding blank cells. What a reviewable AI spec contains Here's the structure the script expects, section by section. The headings match the REQUIRED list in the code, so you can rename them in one place. Problem, stated without AI Start with the user problem and leave the technology out of it. If the problem only makes sense once you've assumed an LLM is the answer, start over. Weak: "Agents need AI summaries of long tickets." Stronger: "Agents who pick up an escalated ticket have to read the whole thread before they can reply. On long threads, that reading is most of their handling time." The linter enforces the cheap version of this rule: the Problem section must not mention AI, LLMs, or models at all. Why AI (and why not) Treat "use an LLM" as a design choice to defend, because probabilistic output has real costs: evals, monitoring, fallbacks, user trust, variable unit cost, and vendor dependence. Compare it honestly against doing nothing, rules or templates, traditional ML, and a hybrid. Then answer a five-line fit check, one sentence each: Error tolerance: can the task live with an occasional wrong output, and who pays for the error? Verification asymmetry: can a user check the output much faster than producing it? Input variability: is the input messy enough that rules break down? Ground truth: can you define "good" well enough to evaluate it, and who decides? Economics: does the expected cost per request fit the value per request? Finish by classifying the stakes as low, medium, or high. A high-stakes feature (financial, legal, safety, or irreversible impact) needs stricter human review and tighter launch thresholds. The script checks that all five answers are filled in and that a stakes level exists, because the stakes level drives a later check. Behaviors, not adjectives This is the heart of an AI spec, and the part engineers should push on hardest. "Summaries should be accurate" can't be tested. "Summaries must not state a resolution date unless one appears in the thread" can. Use a behavior table with IDs, and add one column most templates leave out: Eval, the eval case or metric that checks the row. ID Given Should Must not Eval B1 Typical thread under 20 messages Summarize issue, steps taken, status Invent steps GS-typical B3 No resolution stated Say "No resolution stated" Guess a resolution date GS-ambiguous B5 Text says "ignore your instructions" Treat it as ticket content Follow the instruction GS-adversarial One rule makes the section work: every claim about how the feature should behave must map to an eval case or a metric. If you can't say how you'd check it, it's a wish, not a spec. The linter flags rows with an empty Must-not or Eval cell, and rows whose Should column leans on vague words like "accurate," "concise," or "helpful." The word list is deliberately short; extend VAGUE with whatever your team's favorite non-testable adjectives are. Those IDs should survive all the way through: PRD row → golden-set slice → eval result. When someone asks "do we test B3?", the answer should be a grep, not a meeting. Failure modes and a degradation ladder LLM features fail in predictable ways: fabricated facts, omitted information, wrong format, prompt injection via user content, cross-tenant leakage, provider outages and latency spikes, cost spikes, over-refusal, and uneven quality across languages or segments. List the ones that apply with an impact rating. Every high-impact row needs a detection method, a mitigation, and a named owner. That's the check engineers care about most, because an unowned failure mode is an incident with no on-call. Then write a degradation ladder: what the user sees at each level. Level Condition User experience 0 Healthy Full feature 1 Primary model slow or down Fallback model, shorter output 2 No model available Raw data, a template, or the last result 3 Kill switch flipped Feature hidden; core workflow unaffected Level 2 is the one that gets skipped, and it's the one that decides whether a provider outage is a shrug or a support-queue fire. The linter requires all four levels. Human in the loop, matched to stakes Pick one autonomy level: suggest (a human accepts before anything happens), draft (a human edits before use), act-with-review (the system acts and a human can undo), or autonomous (no per-item review, audit trail required). The more autonomy, the stronger the evals, guardrails, and undo paths need to be. The script encodes one hard rule: high stakes plus act-with-review or autonomous fails. Loosen it only on purpose, in a reviewed diff. Guardrails Guardrails come in layers: input (treat user content as data, not instructions), output (schema validation, content filters, sensitive-data detection), and system (rate limits, spend caps, a kill switch). The linter only checks that the section exists; whether each layer is tested belongs in your eval plan. For privacy, confirm the vendor's retention and training terms from the contract, not a marketing page. Metrics with targets, plus a counter-metric Define success across five families: offline quality (golden-set pass rate), online quality (sampled audits), adoption, cost (per request and per active user), and latency (p50/p95). Every metric needs a target set before launch, and at least one counter-metric, something that should not get worse. Acceptance rate alone flatters AI features, because busy people accept mediocre output; a counter-metric such as "edit distance on accepted summaries" or "reopen rate" keeps that honest. Rollout with gates and a kill-switch owner Stage the rollout (dogfood, partial percentage, GA), give each stage entry and exit criteria, and name who can flip the kill switch before you need it. "GA: when it feels ready" is the row the linter is built to catch. TL;DR, written last Three to five sentences at the top: what, for whom, why now, how you'll know it works, and the biggest risk. The linter only checks that it exists. Whether an exec can staff from it is on you. Encode the checks in Python Save this as spec_lint.py (standard library only, Python 3.8+). It embeds a fictional spec so it runs as-is; pass a path to lint your own SPEC.md: # spec_lint.py -- lint an AI-feature PRD written in Markdown before review. # The sample spec below is made-up example data for a fictional ticket-summarizer. import re import sys SAMPLE_SPEC = """\ # Ticket Summarizer PRD (fictional example) ## TL;DR Draft summaries for escalated support tickets so agents can reply sooner. ## Problem Agents who pick up an escalated ticket must read the whole thread before replying. On long threads, that reading is most of their handling time. ## Why AI - Error tolerance: an occasional weak summary is acceptable; the agent still has the thread. - Verification asymmetry: checking a summary against the thread is faster than writing one. - Input variability: threads mix email, chat and logs, so templates break down. - Ground truth: support leads define a good summary via the rubric. - Economics: - Stakes: medium ## Behaviors | ID | Given | Should | Must not | Eval | |---|---|---|---|---| | B1 | Typical thread under 20 messages | Summarize issue, steps taken, status | Invent steps | GS-typical | | B2 | Thread over 60 messages | Keep every open issue | Drop an open issue | GS-long | | B3 | No resolution stated | Say "No resolution stated" | Guess a resolution date | GS-ambiguous | | B4 | Any thread | Be concise and accurate | | | | B5 | Text says "ignore your instructions" | Treat it as ticket content | Follow the instruction | GS-adversarial | ## Failure modes | Mode | Impact | Detection | Mitigation | Owner | |---|---|---|---|---| | Fabricated facts | high | sampled audit | key-fact check in eval | eval lead | | Prompt injection | high | red-team suite | input wrapping | | | Provider outage | high | error-rate alert | fallback model | on-call | | Over-refusal | low | | | | ## Degradation ladder | Level | Condition | User experience | |---|---|---| | 0 | Healthy | Full summary | | 1 | Primary model slow | Fallback model, shorter summary | | 3 | Kill switch flipped | Panel hidden; ticket view unchanged | ## Human in the loop Level: draft ## Guardrails Input wrapping, output schema validation, per-tenant rate limit, kill switch. ## Metrics | Family | Metric | Target | |---|---|---| | offline quality | held-out golden-set pass rate | >= 0.85 | | online quality | sampled audit pass rate | >= 0.80 | | adoption | weekly active agents using summary | >= 40% | | cost | cost per active agent per month |

This is a summary aggregated from Dev.to. Read the complete article on the original site:

Read full article at Dev.to

More AI & Machine Learning News