Lint Your AI Feature PRD Like Code: A Python Spec Checker for LLM Features A developer published a roughly 190-line standard-library Python linter that checks Markdown PRDs for LLM features for missing sections, requiring behaviors to map to eval cases or metrics and flagging gaps reviewers typically catch late. The tool enforces a behavior table with an Eval column, a problem statement free of AI/LLM mentions, a five-line fit check, and a stakes classification that drives stricter launch thresholds for high-stakes features. The author notes the linter assesses completeness, not quality, and recommends running it in CI against a SPEC.md kept beside feature code. 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. 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. 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. 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. The linter enforces the cheap version of this rule: the Problem section must not mention AI, LLMs, or models at all. 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: 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. 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. 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. 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 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. 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. 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. 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. 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 | <= $0.50 | | latency | p95 time to summary | <= 4s | Rollout | Stage | Entry | Exit | |---|---|---| | Dogfood | eval GO | 1 week, no critical issues | | 10% | dogfood exit met | 2 weeks, audit = 0.80 | | GA | 10% exit met | | Kill switch owner: support-eng on-call """ REQUIRED = "TL;DR", "Problem", "Why AI", "Behaviors", "Failure modes", "Degradation ladder", "Human in the loop", "Guardrails", "Metrics", "Rollout" FIT KEYS = "Error tolerance", "Verification asymmetry", "Input variability", "Ground truth", "Economics" VAGUE = {"accurate", "concise", "good", "high-quality", "helpful", "appropriate"} AI WORDS = re.compile r"\b ai|llm|gpt|model|genai \b", re.I HITL LEVELS = {"suggest", "draft", "act-with-review", "autonomous"} FAMILIES = "offline quality", "online quality", "adoption", "cost", "latency" def sections md : out, name = {}, None for line in md.splitlines : if line.startswith " " : name = line 3: .strip out name = elif name: out name .append line return {k: "\n".join v .strip for k, v in out.items } def table text : rows = l for l in text.splitlines if l.strip .startswith "|" if len rows < 3: return cells = lambda l: c.strip for c in l.strip .strip "|" .split "|" head = h.lower for h in cells rows 0 return dict zip head, cells r for r in rows 2: def lint md : s = sections md results = check, ok, detail missing = r for r in REQUIRED if r not in s results.append "sections present", not missing, "missing: " + ", ".join missing if missing else "" hits = AI WORDS.findall s.get "Problem", "" results.append "problem stated without AI", not hits, "mentions: " + ", ".join hits if hits else "" why = s.get "Why AI", "" blank = k for k in FIT KEYS if not re.search rf"{k}: \t \S", why, re.I results.append "fit check answered", not blank, "blank: " + ", ".join blank if blank else "" m = re.search r"Stakes: \t low|medium|high ", why, re.I stakes = m.group 1 .lower if m else None results.append "stakes classified", bool stakes , stakes or "none" bad = for row in table s.get "Behaviors", "" : bid = row.get "id", "?" words = set re.findall r" a-z- +", row.get "should", "" .lower if words & VAGUE: bad.append f"{bid} vague {', '.join sorted words & VAGUE } " if not row.get "must not" : bad.append f"{bid} no must-not" if not row.get "eval" : bad.append f"{bid} no eval case" results.append "behaviors testable", not bad, "; ".join bad gaps = for row in table s.get "Failure modes", "" : if row.get "impact", "" .lower == "high": empty = c for c in "detection", "mitigation", "owner" if not row.get c if empty: gaps.append f"{row.get 'mode' } missing {', '.join empty }" results.append "high-impact modes owned", not gaps, "; ".join gaps levels = {r.get "level" for r in table s.get "Degradation ladder", "" } lost = str n for n in range 4 if str n not in levels results.append "degradation ladder 0-3", not lost, "missing level " + ", ".join lost if lost else "" m = re.search r"Level: \t a-z- + ", s.get "Human in the loop", "" , re.I hitl = m.group 1 .lower if m else None ok = hitl in HITL LEVELS and not stakes == "high" and hitl in {"act-with-review", "autonomous"} results.append "HITL level fits stakes", ok, f"{hitl} / {stakes}" metrics = table s.get "Metrics", "" fams = {r.get "family", "" .lower for r in metrics} no fam = f for f in FAMILIES if f not in fams no target = r.get "metric" for r in metrics if not r.get "target" counter = any "counter" in r.get "family", "" .lower for r in metrics issues = f"missing family: {', '.join no fam }" if no fam else + \ f"no target: {', '.join no target }" if no target else + \ if counter else "no counter-metric" results.append "metrics complete", not issues, "; ".join issues rollout = s.get "Rollout", "" open stages = r.get "stage" for r in table rollout if not r.get "entry" and r.get "exit" has owner = re.search r"Kill switch owner: \t \S", rollout, re.I issues = f"no entry/exit: {', '.join open stages }" if open stages else + if has owner else "no kill-switch owner" results.append "rollout gated", not issues, "; ".join issues return results def main : md = open sys.argv 1 .read if len sys.argv 1 else SAMPLE SPEC results = lint md for name, ok, detail in results: line = f"{'PASS' if ok else 'FAIL'} {name:<25} {detail}" print line.rstrip failed = sum not ok for , ok, in results print f"\n{len results - failed}/{len results } checks passed - " f"{'READY FOR REVIEW' if not failed else 'NOT READY FOR REVIEW'}" return 1 if failed else 0 if name == " main ": sys.exit main Run it against the embedded fictional spec: bash $ python3 spec lint.py PASS sections present PASS problem stated without AI FAIL fit check answered blank: Economics PASS stakes classified medium FAIL behaviors testable B4 vague accurate, concise ; B4 no must-not; B4 no eval case FAIL high-impact modes owned Prompt injection missing owner FAIL degradation ladder 0-3 missing level 2 PASS HITL level fits stakes draft / medium FAIL metrics complete no counter-metric FAIL rollout gated no entry/exit: GA 4/10 checks passed - NOT READY FOR REVIEW Read the failures the way you'd read a failing test run: counter and a target. The passes matter too. "HITL level fits stakes: draft / medium" is a decision someone made and wrote down, and the linter shows it in the output so a reviewer can disagree with it explicitly. Because main returns 1 on any failure, the script works as a gate with no extra tooling. A minimal step, in whatever CI you use: python3 spec lint.py docs/SPEC.md Two practical notes. First, gate on the spec only for changes that touch the feature's prompts, model config, or the spec itself; you don't want a docs typo blocking an unrelated fix. Second, treat the check list as config: when your team adds a rule say, "every behavior row in a high-stakes spec needs two eval cases" , add it as one more entry in results and review it like any other change. What the linter can't do is equally important. It can't tell you the fit check answers are true, that the eval cases actually test the behaviors they claim to, or that the targets are sensible. It moves the review from "is anything missing?" to "is this right?", and that second question is still a human one. python3 spec lint.py SPEC.md passes, and the output is pasted into the review The linter checks structure; it doesn't write the spec for you. We packaged the structure above into the AI Feature Spec & Eval Kit $29 : an AI-feature PRD template, a fully worked fictional example, an eval plan, a cost and eval workbook, a launch checklist, and an exec and legal one-pager, with behavior IDs that carry from spec to eval: AI Feature Spec & Eval Kit https://mjh4ucorp.gumroad.com/l/ai-feature-spec-eval-kit . Disclosure: we make and sell that kit. You don't need it for anything in this article. The script above will do the completeness check on its own. If you just want the section skeleton, the free AI Feature PRD Template https://mjh4ucorp.gumroad.com/l/ai-feature-prd-template-free has every heading the linter expects, plus guidance prompts and a pre-filled failure-mode table. A PM-focused version of this guide first appeared on the AI Spec Kit Substack https://aispeckit.substack.com/p/how-to-write-a-prd-for-an-ai-feature . Which check would fail first on the last AI spec you reviewed? We'd guess the counter-metric, but we'd like to hear yours. This article was written with the help of AI tools, then reviewed and edited before publishing.