This guide is about numbers: the totals, rates and trends an AI reports from your data. It doesn't cover hallucination in general, such as invented facts or citations. In analytics, a made-up number has three common sources, and each has its own fix.
A wrong number matters more in front of customers. Inside a company, someone may know roughly what a figure should be. A customer can't tell a plausible figure from a real one, and acts on it.
How does an AI make up a number from your data?
- The data doesn't cover the question, and nothing tells the agent to stop. The agent doesn't know what data exists, so it fills the gap with something plausible.
- It doesn't know your definition, so it uses its own. The calculation may be reasonable. It isn't the one your company agreed on.
- The data isn't modeled. The agent joins tables or files no one has described, and the join or the inputs are wrong.
Why does an AI answer when the data doesn't cover the question?
Because nothing shows it what the data covers. An agent sees the tables or passages in front of it, not where the data ends. It can't tell "this isn't in the data" from "I haven't found it yet", so it gives its best guess.
Two common fixes don't change that:
- Retrieval (RAG) finds passages that look relevant and pastes them into the prompt. That helps the agent find one fact, like a product's price. It doesn't tell the agent what is missing. A total over thousands of rows isn't in any passage, so the agent adds up the few rows it got and reports a number that looks complete.
- A prompt rule like "never make up numbers" only works if the agent knows when it is making one up. Without a way to see what the data covers, it doesn't.
A query that matches nothing hides the gap too. On one ecommerce dataset, 255,883 rows have the status 'Complete', with a capital C. A filter for 'complete' runs without an error and matches none of them, so a count returns 0 and the AI reports it as a fact. From our post How an agent turns a question into a trustworthy answer.
What stops it: the agent searches the data model first, and knows what to do when the answer isn't there.
- Search the model before querying. In Malloy Publisher, the
get_contextMCP tool searches your data models for the sources, fields and definitions a question needs. When nothing matches, the agent learns the question isn't modeled before it writes a query. - Tell it what to do when something isn't modeled. The open-source analysis skill tells the agent to search again, then to "say so before continuing rather than quietly working around the gap." Where it may edit the model, the model-as-you-go skill has it add the missing definition instead, so the next session or user finds it modeled. In a customer-facing app, review that addition before customers query it.
- Test that it says so. The eval skills run a set of questions against your model and grade the answers. Include questions the data can't answer, and count "the data doesn't cover this" as a pass.
- Limit what it can query. A Malloy package's
index.malloyexports its sources, and a query that names any other source fails (exports and field visibility). - Show nothing as nothing. Have your app show an empty result or an access refusal as "no data", not as 0 (row and column access).
Why does an AI use its own definition of a metric?
Because yours isn't written anywhere it can read. Asked for "summer sales", one agent in our eval runs used June to August and came in 20% low. The company's season runs from May 25 to September 15. The agent's answer was a reasonable reading of the question. It wasn't the company's. From our post Your Data Model Is Part of Your AI System.
What stops it: write the agreed definitions into a data model the agent reads. In Malloy, an open-source modeling language, a metric is a named, documented line:
source: orders is duckdb.table('orders.parquet') extend {
#(doc) Order revenue, net of refunds.
measure: total_revenue is sum(net_amount)
}Asked about revenue, the agent uses total_revenue instead of deciding what revenue means.
When a question needs a calculation the model doesn't define, the agent can still write one, and should say so. The model-as-you-go skill has it record each judgment call in the model as a named field. The next question reuses that field instead of deciding again, and a person can review it before customers see it.
Why does unmodeled data produce wrong numbers?
Because the agent has to guess how the pieces fit. Two common cases:
- Joins. Six orders total $955 across twelve line items. SQL that joins orders to items and sums the order amount returns $1,445, because each order repeats for every item. From our post The Semantic Layer Is an Interface, Not a Compiler.
- Spreadsheets and hand-built files. A spreadsheet mixes data, formulas and hand-typed values in one place. A typo, a stale value or a formula that stopped one row short is hard to see and hard to check. Join that file to a warehouse table with no model between them, and the agent's answer inherits every hidden error.
What stops it: describe the data before the agent queries it. A data model declares how tables join, so Malloy returns $955 for the same question (Malloy vs. SQL). Values someone types by hand belong in a table or in the model, where a change is versioned and reviewed.
How do you test customer-facing AI before launch?
Ask it questions whose answers you already trust, and compare. Include questions the data can't answer, and count a clear "the data doesn't cover this" as a pass. Keep the questions as an eval and re-run them after every change to the model. How do I know if an AI answer about our data is right? covers what to check.
How should a team start?
The Malloy tools in this guide are open source. Malloy is MIT-licensed. Malloy Publisher serves a model to your app and agents over MCP and an API, with the analysis and eval skills in the same repository. The tutorial gets an agent answering questions over your own files in a few minutes.
To keep each customer to their own rows, see How do you add AI analytics to your app so each customer sees only their own data?
Credible hosts the same models and skills as a managed service. It signs callers in, applies each customer's access rules, and publishes each model change as a version you can roll back to. See pricing.
Frequently asked questions
Does RAG stop an AI chatbot from making up numbers?
No, not for totals, averages or trends. RAG retrieves a few passages and the model writes its answer from them. That works for looking up one fact, like a product's price. A total over thousands of rows isn't in any passage, so the model either adds up what it retrieved or guesses. Numbers like that need a query engine to compute them.
Do structured outputs stop an LLM from making up numbers?
No. Structured outputs make the model's reply match a JSON schema, so a field called revenue always holds a number. Nothing checks that the number is right. The schema controls the shape of the answer, not where the value came from. Have a query engine compute the value, and have your app read it from the query result.
What should a customer-facing AI say when the data can't answer a question?
It should say the data doesn't cover the question, and name what is missing. A plausible figure is the worst answer, because the customer can't tell it from a real one. Give the agent a way to see what the data covers, and instructions to stop and say so when it doesn't.
Why does an AI chatbot report zero when the data exists?
One common cause is a filter that matched nothing. A filter on 'complete' finds no rows when the data says 'Complete', and the query still runs without an error. A count over no rows is 0, and the AI reports it as a fact. Check filter values against the real values in the data, and show no matching rows differently from zero.