11 Ways PRD Alignment With Actual Code Improves AI
Part of the Dead Code guide. Start with The function passed its test. The application never called it.
Suppose a PRD asks for billing reminders. In this hypothetical build, sendBillingReminder() exists, its unit test passes, and the review looks ready, but the helper was attached to a scheduled job that's no longer enabled while the application now starts that flow from a billing event. The function can work perfectly when you call it directly.
The customer still gets nothing.
When I'm checking PRD alignment with actual code, I want the trigger established before anyone starts editing, the requirement compared with the current behavior, and a record of what could actually be verified. The reminder example makes that task specific enough to check.
Before the build: check the PRD's assumptions
1. Turn the requirement into an observable result
“Send billing reminders” leaves too much open. For this example, write down which accounts qualify, the trigger that starts processing, when a reminder should arrive, and what should happen if the same work runs again. These are decisions for whoever owns the feature. Don't let the agent fill them in silently.
2. Find the trigger the application uses today
Start from the repository root with ripgrep's documented search syntax:
rg -F 'sendBillingReminder' .
rg -i 'billing|reminder' .
rg searches the current checkout for these patterns. rg treats the name as a literal string because of -F. The second command broadens the search, neither result tells you which billing path is active, and you need to open the matching registration code, then follow it. In our example, that means finding the event handler and checking whether the old scheduled job is still configured to run.
rg skips hidden files and respects ignore rules by default. ripgrep searches a hidden file or directory named explicitly, and -uu disables both filters during recursive search. If registration might live in hidden or ignored configuration, rerun the search with -uu, check the deployment configuration too, and write down anything you can't inspect, rather than treating no matches as proof that no trigger exists.
3. Read what the existing implementation does
Open the reminder function and the code that decides who receives it. Compare the actual conditions with the PRD, including the account state at processing time, any record of an earlier send, and the outcome when delivery fails. Record file locations alongside the behavior you found.
rg can find references to the function's name. You still need to distinguish its definition from a test call or a registration, then read the relevant source, because a matching line doesn't establish that the required behavior runs, or that it runs under the right conditions.
4. Separate missing work from undocumented behavior
Keep two lists: specified but not built, and built but not specified. In this hypothetical repository, the reminder helper exists, the active event handler doesn't call it, and the inactive old job still contains a reminder call. The PRD says nothing about what should happen to that job.
| Finding | What to record before coding |
|---|---|
| Specified but not built | The required event doesn't invoke the reminder helper. Add that connection to the implementation plan. |
| Built but not specified | The inactive scheduled path contains a reminder call. Ask whether to retire it or retain it for a defined purpose. |
The second list needs a decision. Don't automatically delete something because the PRD omits it, and don't silently preserve it either, especially if keeping the old trigger could send the same reminder twice, or if someone still relies on it.
5. Resolve the disagreement before asking for code
Choose the intended trigger and update the PRD with that decision. If the event path wins, say what happens to the scheduled path, who qualifies when the event is processed, and how repeated processing should behave, so the implementation doesn't inherit two conflicting versions of the feature.
For help gathering the repository evidence an agent needs, use the guide to giving an AI agent codebase context.
6. Ask for a plan with evidence and open questions
I would ask the agent for this before letting it edit:
Compare the billing-reminder requirement with this checkout.
For each acceptance criterion, cite the relevant file and function.
Separate specified-but-not-built from built-but-not-specified.
Identify the current trigger and any competing older trigger.
Mark unverified assumptions and decisions I need to make.
Propose the smallest change after those decisions are resolved.
Ask it to keep observed facts separate from proposed changes, cite where it looked, and leave a criterion unresolved when the evidence is missing, even if that makes the plan less tidy. A confident guess about a scheduler setting doesn't belong in the implementation plan as a fact.
After the build: check the result against the same criteria
7. Check the changed code in the working branch
Repeat the name search against the checkout containing the new code:
rg -F 'sendBillingReminder' .
rg now searches the version you're reviewing. Open the changed handler, confirm that it calls the helper under the agreed conditions, inspect the old job's disposition, and keep the review tied to that branch. A search of an older checkout won't establish what this change did.
8. Exercise the agreed trigger
Run the feature through its intended entry point in a test environment. For the event-based version, arrange a qualifying account, deliver the relevant event to the application, and observe the resulting reminder, rather than calling sendBillingReminder() directly and assuming that covers the integration.
Use the smallest environment that exercises that connection, keep the helper test too, and, if you're unsure what the extra check adds, see our example of a feature that was built but never wired in.
9. Check the cases that could change the answer
Try an ineligible account and repeat the same event. Compare the observed results with the decisions in the PRD, test the failure behavior you agreed on, and check what the older scheduled path now does, particularly if you've retained it. Keep the inputs with the test result so someone else can repeat the check.
10. Update the two lists with what you observed
Move a missing item to complete only when you have evidence for its acceptance criterion, attach the test or review result, and keep anything untested visible, including deployment settings you couldn't access. The function's presence is evidence that code exists. Completion needs the behavior the PRD asked for.
rg can help locate the implementation and its test files again. It doesn't execute the feature or establish which configuration is deployed.
11. Record the revision you're approving
Put the reviewed revision beside the results. If the code changes after that check, revisit the affected criteria, and if the release uses different configuration, check that configuration before calling the rollout complete. “Verified on this revision in this environment” is a more useful handoff than “the AI finished it.”
For broader review habits beyond this checklist, see reducing mistakes in AI-assisted coding.
Where Pharaoh fits, and what still needs checking
I build Pharaoh. Its get_module_context tool returns a module's exports and endpoints, cron jobs, and callers from other modules, so an agent can inspect that structure while comparing the requirement with the repository. The code graph MCP server guide explains that interface.
The following real output comes from get_unused_code, with checkAdminOrOwner supplied in the functions parameter, on revision 54343aa6 of Pharaoh-so/cal.diy, and concerns an authorization helper rather than our hypothetical billing feature. The block below is complete.
# Reachability in cal.diy
- checkAdminOrOwner (packages/features/auth/lib/checkAdminOrOwner.ts): reachable: getAtomEventTypeApp → getEventTypesAppIntegration → checkAdminOrOwner
That result supplies a detected call chain. It doesn't establish the billing requirements in our example, prove delivery to a customer, or resolve a disagreement about which trigger the product should use, so keep those acceptance checks in the review. The feature-wiring documentation covers the structural check.
Pharaoh's map covers the default branch, with a live repository remapped after pushes to that branch, so it doesn't describe your uncommitted changes, or a feature branch. Use the local review above for the build in progress, and check the mapped version when you're using graph evidence. If you'd like the map in your agent, connect a repository to Pharaoh, inspect the module involved, and compare what you find with the PRD.
Start with the reminder's trigger. Keep the unresolved requirement visible until someone decides it, then check the actual flow on the revision you're going to ship.