# AI Grounding: One Question, Before and After

> AI grounding ties a model

[Home](https://quanticdata.io/) / [Blog](https://quanticdata.io/blog/) / AI Grounding: One Question, Before and After

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

Data for AI · Nov 20, 2026 · 9 min read · By [Aldo Morese](https://quanticdata.io/about/), founder of QuanticData

![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.](https://quanticdata.io/blog/ai-grounding/hero.webp?v=20261120h)

On this page

- [What AI grounding means](https://quanticdata.io/blog/ai-grounding/#what-ai-grounding-means)
- [Grounding vs RAG vs agentic RAG](https://quanticdata.io/blog/ai-grounding/#grounding-vs-rag-vs-agentic-rag)
- [The test: one question, before and after](https://quanticdata.io/blog/ai-grounding/#the-test-one-question-before-and-after)
- [What came back](https://quanticdata.io/blog/ai-grounding/#what-came-back)
- [The citation check, in code](https://quanticdata.io/blog/ai-grounding/#the-citation-check-in-code)
- [A second question, and when to ground](https://quanticdata.io/blog/ai-grounding/#a-second-question-and-when-to-ground)
- [Grounding sources other than web search](https://quanticdata.io/blog/ai-grounding/#grounding-sources-other-than-web-search)
- [Run it yourself](https://quanticdata.io/blog/ai-grounding/#run-it-yourself)

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.

**Run it on the free credit.** Every QuanticData account gets $2 of free API usage per month.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-lead&utm_content=ai-grounding) · [Explore Web Data API for AI Agents](https://quanticdata.io/web-data-api-for-ai/)

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](https://quanticdata.io/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](https://quanticdata.io/blog/give-ollama-internet-access/) and [Qwen web search over MCP](https://quanticdata.io/blog/qwen-web-search-mcp/). The wider choice between context, RAG, tools and fine-tuning is covered in [how to feed data to an LLM](https://quanticdata.io/blog/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:

```python
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.

**Try it on your own targets.** Every QuanticData account gets $2 of free API usage per month.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-inline&utm_content=ai-grounding) · [Explore Web Data API for AI Agents](https://quanticdata.io/web-data-api-for-ai/)

## 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](https://quanticdata.io/mcp-server/), or the [SERP API for AI agents](https://quanticdata.io/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](https://quanticdata.io/blog/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](https://quanticdata.io/blog/local-llm-web-search-mcp/) 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](https://quanticdata.io/web-data-api-for-ai/) returns pages as Markdown or JSON from a plain HTTP call.

### Sources & further reading

- [Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (arXiv:2005.11401)](https://arxiv.org/abs/2005.11401)
- [Model Context Protocol specification: Transports (streamable HTTP)](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports)
- [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk)
- [Ollama API: generate a chat completion](https://github.com/ollama/ollama/blob/main/docs/api.md)
- [Python Developer's Guide: Status of Python versions](https://devguide.python.org/versions/)

## FAQ

Quick answers on ai grounding.

[Something else? Ask us](mailto:hello@quanticdata.io)

### 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.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-end&utm_content=ai-grounding) · [Explore Web Data API for AI Agents](https://quanticdata.io/web-data-api-for-ai/)

## Related reading

- [IPv6 Proxies for AI Training Data and Agents](https://quanticdata.io/blog/ipv6-proxies-for-ai-training-data/): Data for AI · A DNS probe of the sources AI pipelines pull from and of the model API hosts agents call: which ones an IPv6 proxy reaches, which are IPv4-only, the routing rule that sends each fetch to the cheapest network that works, and the cost of a corpus at $0.20/GB versus residential.
- [Best YouTube Transcript APIs Compared (2026)](https://quanticdata.io/blog/youtube-transcript-apis-compared/): Data for AI · We read the same three videos through our Video API and ran the open-source Python package from a cloud server, then set six options side by side: what one call returns, frames and chapters, what happens when YouTube blocks the IP, billing, free tier and MCP.
- [n8n Assistant Web Search Setup](https://quanticdata.io/blog/n8n-assistant-web-search-quanticdata/): Data for AI · A local adapter connects QuanticData SERP search to the SearXNG setting in n8n Assistant. We tested the installed n8n client against the real API and received ten results with titles, URLs and snippets.

---

Source: https://quanticdata.io/blog/ai-grounding/ · Site index for AI: https://quanticdata.io/llms.txt
