Grounding: Make the AI Answer Only from Your Documents
LLMs tend to always answer, even if they have to make things up. Grounding forces them to stick to your sources. Learn the two key instructions and how to verify the answers.
Imagine you're a product manager at a financial institution building a business case for a mobile app, and you need to understand the applicable regulation. The goal isn't to replace the legal team but to arrive with more mature proposals, so lawyers spend their time on how to make your idea feasible rather than explaining the law from scratch. LLMs help with this, but only if you control their answers.
What is grounding?
It's a technique that forces the model to answer exclusively from the information you provide, instead of using its general knowledge or inventing data. Why is it needed? Because LLMs have a natural tendency to always answer, and if that means fabricating information, they will (hallucination).
There are two mechanisms:
- Be explicit about the source. Example: "Base your answer ONLY on the attached document of the Credit Institutions Law." Capitalizing "ONLY" adds emphasis, like someone raising their voice to stress a point, and naming the document reduces the chance that the model treats another source as valid.
- Give a contingency instruction. Example: "If the information is not in the document, answer that it is not available." Without it, the model looks for patterns even where none exist and invents an answer.
Base your answer ONLY on the attached document: [document name]. If the information is not in the document, respond that it is not available.Test it: when the information doesn't exist
In the class example, the question was about the authentication requirements for a mobile app, using only the Credit Institutions Law. The model correctly answered that the information was not available. Both mechanisms worked: it acknowledged missing data instead of making something up.
Using multiple documents as context
Uploading several documents gives more complete answers. In the example, three sources were used: the Credit Institutions Law, Annex 63 (electronic banking) and an Official Gazette (Diario Oficial de la Federación).
Validate with verbatim quotes
Ask the model to include the exact quote from the source, in quotation marks, for each requirement it mentions. That way you can go straight to the source document and verify that the information exists.
Heads up: quotes are not always exact. In class, searching the original PDF for a quote from Annex 63 failed because of special characters in the document; searching for keywords (e.g., "user's mobile phone") found the passage, with similar but not identical content.
- Search for the full quote.
- If it doesn't appear, search for fragments or keywords.
- Compare the content to confirm it is consistent with the claim.
Avoid omission errors across documents
The risk: the model may focus on one document and ignore the others (a hallucination by omission). In the example, asked about information custody, the model cited only the Official Gazette. When asked explicitly whether the Credit Institutions Law mentioned it, it confirmed the term did not appear there.
- Cross-validate by asking directly about each document.
- Improve the original prompt by stating that all attached documents must be consulted in every answer.
Checklist for grounded prompts
- Did I name the source documents explicitly?
- Did I include the "ONLY" restriction?
- Did I add the "not available" fallback instruction?
- Does the wording match the number of documents (singular or plural)?
- Did I request verbatim quotes for every claim?
- Did I require all documents to be consulted in every answer?
- Did I spot-check the quotes against the originals?
Key takeaways
- Grounding turns the LLM into a reliable assistant, not an infallible oracle.
- Name the source, use "ONLY" and give a contingency ("not available").
- Adapt the prompt to the number of documents you upload.
- Ask for verbatim quotes and verify them, searching by keyword if the exact quote fails.
- Cross-validate between documents to catch omissions.