AI grounding means giving a language model the sources for its answer at the moment you ask, and making it answer only from them, with a citation for each fact. We tested it on 20 November 2026: asked for the latest Python release, a local model said 3.12.0; given three live web pages, it said 3.15.2 and cited them.
Most pages on the topic stop at the definition. This one shows the whole thing done: the script, the two answers, the sources and a check that every number in the answer is in the page it cites. The model ran on our own PC through Ollama; the sources came from the QuanticData MCP server, called from Python.
What AI grounding means
A language model answers from what it learned in training. That knowledge stops at a cutoff date and has no record of where each fact came from, so the model can be out of date, and it can produce a confident answer with nothing behind it. Grounding changes where the facts come from:
- Retrieve. Before the model answers, fetch text that holds the answer: your documents, a database, or live web pages.
- Constrain. Put that text in the prompt as numbered sources and tell the model to answer only from them, and to say so when they do not contain the answer.
- Cite and check. Make the model mark each fact with its source number, then check the marks in code: a citation that points nowhere, or a number that is not in the cited source, is caught before anyone reads the answer.
The last step is the one most explanations leave out, and it is the one that turns "the model saw some sources" into an answer you can verify.
Grounding vs RAG vs agentic RAG
The terms overlap, and the difference is which part decides when to fetch:
| Term | What it is | Who decides what to fetch |
|---|---|---|
| Grounding | The goal: every claim in the answer traceable to a source | Any of the methods below |
| RAG (retrieval-augmented generation) | A fixed pipeline: retrieve for every question, then generate from what came back | Your code, before the model runs |
| Agentic RAG | The model gets a search tool and calls it when, and as often as, it decides to | The model, during the conversation |
| Fine-tuning | Training the model further on your data | Nobody at question time: no sources, no citations |
A RAG chatbot is the same pipeline run on every turn of a chat. The run below is plain RAG with live web search as the retriever, because it is the easiest to read and to check. The agentic version, where the model calls the search tool itself, is in our guides to give Ollama internet access and Qwen web search over MCP. The wider choice between context, RAG, tools and fine-tuning is covered in how to feed data to an LLM.
The test: one question, before and after
We picked a question with a fresh, checkable answer: "What is the latest stable version of Python, and when was it released?" The setup, all on one Windows 11 PC:
- Model: qwen2.5:14b in Ollama, temperature 0, so the run is repeatable.
- Retriever: the search_and_read tool of our MCP server, which searches the web, reads the top pages and returns them as numbered sources with one context string ready for a prompt. We used Bing as the engine and the top 3 pages.
- Client: Python 3.12 with the official MCP Python SDK (mcp 1.27.2), connecting over streamable HTTP with an API key.
The retrieval step, as it ran:
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
MCP_URL = "https://api.quanticdata.io/mcp"
async def search_and_read(query):
headers = {"Authorization": f"Bearer {os.environ['QUANTICDATA_API_KEY']}"}
async with streamablehttp_client(MCP_URL, headers=headers) as (read, write, _):
async with ClientSession(read, write) as session:
await session.initialize()
res = await session.call_tool("search_and_read", {"query": query, "engine": "bing", "top_n": 3, "max_tokens": 4000})
return json.loads(res.content[0].text)
The grounding step puts the context in the system prompt with three rules: only these sources, cite each fact as [n], say so if the answer is not there.
system = ("Answer the question using ONLY the numbered sources below. After each fact, cite its source as [n]. "
"If the sources do not contain the answer, say so.\n\n" + context)
gans, pin, pout = ollama([{"role": "system", "content": system}, {"role": "user", "content": QUESTION}])
The ollama() helper is a POST to http://localhost:11434/api/chat with stream: false, temperature: 0 and num_ctx: 16384, so the sources fit in the context.
What came back
The real output of the run on 20 November 2026 (timings left out):
Question: What is the latest stable version of Python, and when was it released?
Model: qwen2.5:14b
--- 1. Ungrounded answer (44 prompt tokens)
As of my last update in October 2023, the latest stable version of Python is Python 3.12.0,
which was released on September 25, 2023. However, to get the most current information, you
should check the official Python website or the Python release page.
--- 2. search_and_read: 3 sources, context 15393 chars
[1] Download Python | Python.org (1270 tokens) https://www.python.org/downloads/
[2] Python documentation by version | Python.org (1270 tokens) https://www.python.org/doc/versions/
[3] Status of Python versions (1246 tokens) https://devguide.python.org/versions/
--- 3. Grounded answer (5865 prompt tokens)
The latest stable version of Python is 3.15, which is in the bugfix phase. The first release of
Python 3.15 was on 2026-10-09 [2][3]. The most recent release of Python 3.15 as of the information
provided is Python 3.15.2, which was released on 25 October 2026 [2].
--- 4. Grounding check
citations used: [2, 3]; citations with no source: none
numbers in the answer: ['2026', '3.15', '3.15.2']; not found in the sources: none
numbers not in the source they cite: none
Three things to read in it:
- The ungrounded answer is not wrong for its time, it is old. 3.12.0 was the release the model knew about. It even says to check the official site, which is the step grounding automates.
- All three sources are primary. Two pages of python.org and the Python Developer's Guide, the places a careful person would check by hand.
- The answer costs context. 44 prompt tokens became 5,865: three pages of text. The
max_tokenssetting of search_and_read is how you keep that inside the model's window.
The citation check, in code
A grounded answer is only as good as its citations, so the script checks them instead of trusting them. It splits the context into its numbered sources, then, sentence by sentence, looks for each version number or year in the source that sentence cites:
blocks = {int(m.group(1)): m.group(2) for m in re.finditer(r"^\[(\d+)\] (.*?)(?=^\[\d+\] |\Z)", context, re.S | re.M)}
wrong = []
for sent in re.split(r"(?<=[.!?])\s+", gans):
refs = [int(n) for n in re.findall(r"\[(\d+)\]", sent)]
for num in re.findall(r"\d+(?:\.\d+)+|\b\d{4}\b", sent):
if refs and not any(num in blocks.get(r, "") for r in refs):
wrong.append(f"{num} cited to {refs}")
It is a narrow check: it covers numbers, not every word. For answers whose value is in the numbers (versions, prices, dates, counts) it catches the two failures that matter, a citation to a source that does not exist and a figure the cited source does not contain. For prose, a second model call that asks "does source [n] support this sentence, yes or no" does the same job.
A second question, and when to ground
We ran the same script with a question from after the model's training: "Who won the 2026 FIFA World Cup final, and what was the score?"
| Python release | 2026 World Cup final | |
|---|---|---|
| Ungrounded answer | 3.12.0, released 25 September 2023 | "has not yet taken place" |
| Sources returned | 3: python.org (2), Python Developer's Guide | 3: Wikipedia, a World Cup reference site, fifa.com |
| Grounded answer | 3.15.2, 25 October 2026, cited [2] | Spain 1-0 Argentina, cited [1][2] |
| Prompt tokens, ungrounded and grounded | 44 and 5,865 | 48 and 4,536 |
| Citation check | clean | clean |
Ground the answers where the right answer changes or has to be shown: versions, prices, schedules, results, rules, anything a user will act on. Skip it for questions the model answers well on its own, such as explaining a concept or writing code from a clear description, where three pages of context add cost and no accuracy.
Grounding sources other than web search
Web search is one retriever. The same prompt and the same check work with any of these:
| Source | Good for | How it reaches the prompt |
|---|---|---|
| Live web search and page reading | Public facts that change: releases, news, prices, documentation | search_and_read on our QuanticData MCP server, or the SERP API for AI agents plus a page reader |
| Known pages | A fixed set of URLs you trust, read fresh each time | A scrape tool that returns Markdown, as in our MCP web scraper test |
| Your own documents | Policies, manuals, tickets | A vector index: embed, search, put the top chunks in the prompt |
| Structured data | Exact figures: stock, prices, account data | A database query or API call whose result goes in as a source |
Two settings matter most with a web retriever. Keep the context inside the model's window: we set max_tokens to 4,000 and num_ctx to 16,384, and our tests of local LLM web search show what fits at smaller sizes. And pick the engine and the number of pages per question: three pages were enough for both questions here.
Run it yourself
- Install the MCP Python SDK:
pip install mcp. - Pull a model in Ollama, for example
ollama pull qwen2.5:14b, or point the helper at any chat API you use. - Create an API key in your QuanticData account and set it as
QUANTICDATA_API_KEY. - Run the script with your question as the argument, and keep the check: it is seven lines and it is what makes the answer something you can show.
For pipelines that ground answers at volume, the web data API for AI returns pages as Markdown or JSON from a plain HTTP call.

![The same three YouTube videos read on 20 October 2026: a comparison grid of six transcript options with the frames column lit, and the QuanticData Video API card with the transcript as spoken and [m:ss] stamps, 12 and 25 chapters as headings, 12 frames of 160×90 per read and 1.7 to 7.3 seconds per read; the open-source package was blocked 9 of 9 times from a cloud server.](../youtube-transcript-apis-compared/hero-card.webp?v=20261020h)
