An LLM asked to "write tests for the payments screen" will happily invent plausible-looking steps that have nothing to do with your actual product. The fix is the same one that works everywhere else: don't ask the model to remember, give it the source of truth to read.

Grounding the agent

We index the artefacts engineers already write — product requirement docs, OpenAPI schemas, component contracts and past defects — into a vector store. Before generating a single step, the agent retrieves the passages relevant to the flow under test and conditions on them. The result is a script grounded in this release, not in the model's training data.

retriever.py
context = retriever.search(
    query=f"acceptance criteria for {flow}",
    k=8,
)
steps = generate_test(flow, context=context)

Self-healing selectors

Grounding also makes healing far more reliable. When a locator breaks, the agent re-retrieves the current DOM and the component contract, then reconciles the two. Because it reasons over the real structure instead of guessing, the proposed fix usually holds — and every heal is logged for a human to confirm or reject.

PRDs to test scripts isn't a party trick. It's the shortest path to coverage that tracks the product instead of lagging weeks behind it.