Skip to lesson
Exit
AI-Editor Systems & Design1 / 3

2 min lesson

Grounding is the biggest lever

Recall the main items in "Grounding is the biggest lever", then connect each one to the work.

Step 1 of 3

Grounding is the biggest lever

Most code hallucination is the model filling a gap in its context with a plausible guess. Give it the real signature of the function it's calling and the guess has nowhere to go. This is why retrieval (section one) and hallucination control are the same problem viewed from two ends.

  • Feed exact symbol definitions and types so the model references reality, not its training-data memory of a similar library.
  • Constrain to a structured edit format the system can parse and validate, rejecting anything malformed before it reaches the buffer.
  • Prefer tool calls (read the file, search the docs) over the model recalling an API from memory.
Learn more

Full explanation

Verification: the loop that earns trust

Verification: the loop that earns trust

The cheapest, most reliable hallucination filter is the compiler. Code is special among LLM outputs: you can often check it mechanically. Lean on that hard.

  1. 1Type-check / compile the proposed edit. A change that doesn't build is wrong, full stop, no model judgment required.
  2. 2Run relevant tests where they exist; a passing suite is strong evidence the edit preserved behavior.
  3. 3Feed failures back into the agent loop so it fixes its own mistake before the user ever sees it.
  4. 4Escalate the unverifiable. When nothing mechanical can check it, mark it uncertain and lean on the review UX rather than pretending it's verified.
Make wrong cheap, not impossible

You will never get to zero hallucination, so the product goal shifts: make a wrong suggestion cost the user almost nothing. A clear diff, an obvious reject and surfaced uncertainty turn a hallucination from a trust-breaking incident into a half-second "no thanks." The review surface isn't polish; it's the safety system.

Interview move

If you get "how would you address hallucinations in a deployed model," answer in three moves and name them: reduce with grounding and constrained outputs, catch with compile/type-check/test in the loop and make residual errors cheap to reject with a diff and surfaced uncertainty. Calling the compiler your most reliable grader signals you know code is checkable in ways prose isn't.

Say it like this

“I assume the model will be wrong sometimes, so I design three layers. I ground it in retrieved symbols so it has less to invent, I verify edits with the compiler and tests in the agent loop so wrong ones get caught and retried and I make whatever survives land as a diff the user can reject in one keystroke. Correctness in a probabilistic system is an architecture, not a better prompt.”

Learn more

Optional practice

Practice: Grounding is the biggest lever

QWhy is code an unusually favorable output to defend against hallucination and how do you exploit that in the agent loop?