Documentation Python quickstart Blog Free tools Enterprise solutions hello@quanticdata.ioLog in

AI grounding: what it is, how it differs from RAG, and a real run with live web sources

A Python script on a Windows PC asks a local qwen2.5:14b model for the latest Python release: the model calls search_and_read on the QuanticData MCP server, gets three numbered sources and answers 3.15.2 with a citation; the card compares the ungrounded answer 3.12.0 with the grounded one and shows the citation check passing with no number outside its cited source.
A Python script on a Windows PC asks a local qwen2.5:14b model for the latest Python release: the model calls search_and_read on the QuanticData MCP server, gets three numbered sources and answers 3.15.2 with a citation; the card compares the ungrounded answer 3.12.0 with the grounded one and shows the citation check passing with no number outside its cited source.

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:

TermWhat it isWho decides what to fetch
GroundingThe goal: every claim in the answer traceable to a sourceAny of the methods below
RAG (retrieval-augmented generation)A fixed pipeline: retrieve for every question, then generate from what came backYour code, before the model runs
Agentic RAGThe model gets a search tool and calls it when, and as often as, it decides toThe model, during the conversation
Fine-tuningTraining the model further on your dataNobody 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_tokens setting 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 release2026 World Cup final
Ungrounded answer3.12.0, released 25 September 2023"has not yet taken place"
Sources returned3: python.org (2), Python Developer's Guide3: Wikipedia, a World Cup reference site, fifa.com
Grounded answer3.15.2, 25 October 2026, cited [2]Spain 1-0 Argentina, cited [1][2]
Prompt tokens, ungrounded and grounded44 and 5,86548 and 4,536
Citation checkcleanclean

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.

Web search is one retriever. The same prompt and the same check work with any of these:

SourceGood forHow it reaches the prompt
Live web search and page readingPublic facts that change: releases, news, prices, documentationsearch_and_read on our QuanticData MCP server, or the SERP API for AI agents plus a page reader
Known pagesA fixed set of URLs you trust, read fresh each timeA scrape tool that returns Markdown, as in our MCP web scraper test
Your own documentsPolicies, manuals, ticketsA vector index: embed, search, put the top chunks in the prompt
Structured dataExact figures: stock, prices, account dataA 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

  1. Install the MCP Python SDK: pip install mcp.
  2. Pull a model in Ollama, for example ollama pull qwen2.5:14b, or point the helper at any chat API you use.
  3. Create an API key in your QuanticData account and set it as QUANTICDATA_API_KEY.
  4. 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.

Sources & further reading

FAQ

Quick answers on ai grounding.

Something else? Ask us

What does grounding mean in AI?

Grounding means giving a model the sources for its answer at request time, telling it to answer only from them and to cite each fact. In our test, a local model asked for the latest Python release said 3.12.0 on its own and 3.15.2, with citations, when given three live pages.

What is the difference between AI grounding and RAG?

Grounding is the goal: every claim traceable to a source. RAG is one way to reach it: retrieve text for each question, then generate from it. Agentic RAG lets the model call the search tool itself. Fine-tuning changes the model but gives no sources to cite.

How do you ground an LLM with web search?

Search the web for the question, read the top pages, put them in the prompt as numbered sources and tell the model to answer only from them with [n] citations. We did it with the search_and_read tool of the QuanticData MCP server, called from Python, and a local model in Ollama.

How do you check that an AI answer is grounded?

Check the citations in code. Every [n] must point to a source that exists, and every number in a sentence must appear in the source that sentence cites. Our check is seven lines of Python; for prose, ask a second model call whether source [n] supports each sentence.

Does grounding stop hallucinations?

It reduces them and makes the rest visible. The model can still misread a source, which is why the answer carries citations and the citations are checked. Grounding cannot help when the sources themselves are wrong, so prefer primary sources: in our run all three were official Python pages.

How much does grounding add to the prompt?

The text of the sources. In our runs the prompt grew from 44 to 5,865 tokens for three pages, and from 48 to 4,536 for the second question. A token limit on the retrieved context keeps it inside the model's window.

Live web sources for your model

Search, read and cite the web from any MCP client or a plain HTTP call, with pages returned as clean Markdown with a token limit you set.

Related reading