Prompt engineering to curb extraction hallucinations
Practical hallucination control plus honesty about limits.
Ground strictly in source, allow null for missing fields, enforce a schema, and use few-shot examples; acknowledge prompting cannot fully eliminate it.
What's really being asked
Whether you can apply concrete prompting techniques to extraction and, just as importantly, state where prompting stops being enough.
The full answer
PROMPTING TECHNIQUES. Tell the model to extract only information explicitly present in the source and to output null or not found rather than inventing a value for missing fields, which removes the pressure that drives confabulation. Constrain the output to a strict schema, ideally enforced with JSON or structured-output decoding, so the model fills fixed slots instead of free-forming. Provide few-shot examples that resemble the real documents, including examples where some fields are genuinely absent so the model learns to emit null. Ask the model to attach the verbatim source span for each extracted value, which both improves grounding and gives you a check. Lowering temperature reduces some random invention. LIMITATIONS. Prompting changes the distribution but offers no guarantee; the model can still confidently fabricate, especially on document layouts unlike your examples. Prompts are brittle and can regress when documents shift. They do not verify correctness. For dependable extraction you need validators that reject malformed or unsupported outputs, retrieval grounding, and ideally a second-pass verification that confirms each value appears in the source.
The mistakes people make
Claiming a clever prompt eliminates hallucination. Not allowing a null option, forcing the model to guess. Omitting a schema. Ignoring that prompting needs an external verification layer. Assuming test-set success generalizes to all new documents.
What usually comes next
Why does allowing null reduce hallucination? How would structured-output decoding help? What verification layer would you add beyond prompting? How do you detect regressions on new document types?
A concrete example
Extracting invoice_total from a document lacking that field, a naive prompt makes the model guess a plausible number. Revised, the prompt says return null if the value is not explicitly present and attach the source text, plus a few-shot example with a missing total mapped to null. The model now returns null with no span. A downstream validator confirms each non-null value's span actually exists in the source, catching any residual fabrication that prompting alone missed.
Interview question
Why does explicitly allowing the model to output null for absent fields reduce hallucination during structured extraction?
- a.It disables the model's ability to generate any new text
- b.It forces the model to re-read the document from scratch each time
- c.It guarantees the output schema is always valid
- d.It removes the implicit pressure to produce a value, giving the model a valid way to signal missing informationCorrect
Why? this is the answer
When no null option exists, the model tends to invent a plausible value; permitting null lets it correctly signal absence. It does not re-read input or guarantee schema validity, and prompting cannot fully eliminate hallucination.
Just read this? Test yourself on what you have been reading.
- #llm
- #hallucination
- #prompt-engineering
- #structured-extraction
- #reliability
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on llm — each one lists the topics its interview covers.
See open roles