Apply to my task
arXiv:2604.25149 ★ 92 Apr 28, 2026

Semantic Layer: A Business-Context Document Doubles LLM Accuracy in Data Analysis

Key result

Is the `SalesAmount` column in your table revenue before returns or after? Is region the customer's or the warehouse's? The LLM sees a bare schema and guesses. It gets it right about half the time. The semantic layer method lets you analyze data so that the model applies your business logic instead of inventing its own. Add 1-2 pages of markdown with metric definitions before the data and the question, and accuracy jumps by 17-23 percentage points. The difference between Claude and GPT is pocket change. The difference between "with context" and "without" is huge.

01

TL;DR

When an LLM analyzes your data (tables, reports, databases) and your prompt only explains what you want to know, the model starts guessing what your metrics mean. Instead, you can hand it a short document: what "revenue" means in your specific table, how margin is calculated, which order statuses count. The study calls this a semantic layer, a layer of meaning.

Without such a document the model answers correctly in roughly half the cases. That happens because a data schema stores no business logic, only structure. Column names like SalesAmount or FactOnlineSales don't tell you: is this all sales or just online? Are returns subtracted? Is "region" the customer's region or the store's? The model sees a bare structure and has to guess.

Adding 1–2 pages of explanations to the same data lifts accuracy by 17–23 percentage points, whether you're using Claude or GPT. And that's the key insight: the gap between models is negligible, while the gap between "with context" and "without context" is huge.

Want this for your own case? Apply this study to your task: AI adapts its method to what you are working on and writes the prompt.

02

Method Blueprint

STEP 1: Write a semantic document → 1-2 pages of markdown with the rules of your table
        (what counts as "revenue," how to treat ambiguous statuses, which columns are responsible for what)

STEP 2: Put the document + data + question into one prompt → an answer with the correct business logic

Everything happens in a single prompt, no separate requests.
03

Example

Task: You're on the team of an Amazon seller. You want Claude to analyze the weekly sales report. The table has orders, keep_rate, gross_sales, fees, returns. Without context Claude starts guessing: is "gross sales" revenue or GMV? Is "keep rate" a percentage or an absolute number? Which orders should the date filter apply to?

Prompt:

## Business context (semantic layer)

**Metrics and their definitions:**
- "Orders": number of placed orders regardless of status
- "Keep rate": orders delivered and kept by the customer divided by all delivered orders; expressed as a percentage; excludes orders with status "in transit to customer"
- "Gross sales": total of all orders at selling price, before returns and fees
- "Net revenue": gross sales minus returns minus the Amazon referral fee (15%)
- "Return": any order with status "refused on delivery" or "returned to warehouse"

**Table conventions:**
- The date in the `order_date` column is the order date, not the delivery date
- If `promo_code` is empty, the order had no promotion
- The `region` column is the customer's region, not the warehouse's

**Rule for "the latest period":**
- If I ask "for the week," take the last 7 days counting back from the maximum date in the table, not from today

---

## Data
[paste the table or CSV]

## Question
Which 5 SKUs generated the most net revenue over the last 2 weeks? Show gross sales, returns and final net revenue for each.

Result: The model applies your definitions literally: it calculates net revenue using the formula from the document, takes the correct period from the maximum date, and doesn't confuse gross sales with revenue. Without the document there's a ~50% chance it would guess wrong, for example treating gross sales as revenue or counting dates from "today."

04

Why It Works

LLMs are good at applying explicitly written rules. They're bad at guessing rules from data structure. Those are different tasks, and the semantic layer turns "guess what this column means" into "take the definition from the document."

A data schema tells you what exists. A semantic layer tells you what it means and how to use it. The gap between the two is the source of most data-analysis errors. According to the study, more than 80% of errors when LLMs work with data are exactly this type: wrong column, wrong aggregation, wrong interpretation of a term.

The key lever: you're not making the model smarter, you're changing the task itself. "Guess the business logic from a bare schema" → "apply explicitly written business logic." These are fundamentally different instructions.

Control levers: - Level of detail in the document → more detail = less guessing. Start with the 5-7 least obvious metrics - Disambiguation rules → if a term can mean two different things, write down both readings and the rule for choosing - Data conventions → string booleans ('Yes'/'No' instead of 1/0), "latest period" dates, sentinel values: spell them out - Which table to use for what → if you have several data sources, state the priority

05

Prompt Template

## Semantic layer

**Metric definitions:**
- "{metric_1}": {what it means, how to calculate it, what to include/exclude}
- "{metric_2}": {what it means, how to calculate it}

**Table conventions:**
- Column "{column}" means {what}, not {what it could be confused with}
- If field {field} is empty, {how to interpret it}
- The period "last {period}" is counted from {starting point}

**Rules for resolving ambiguity:**
- If the question says "{term}", use {which source/metric exactly}
- If no dates are given, use {default period}

---

## Data
{paste the table, CSV or a description of the structure}

## Question
{your question}

Placeholders: - {metric} — the key metrics in your field: revenue, conversion, LTV, keep rate - {column} — the column names in your table - {period} — typical time-based asks: "week," "quarter," "last month" - {term} — words with a double meaning in your context


🚀 Quick start — paste into the chat:

Help me put together a semantic layer for my data.
Ask me questions one at a time so I can fill in the template.
My task: [describe your task: what the data is and what you want to do with it]

[paste the template above]

The LLM will ask for your metric names, what they mean, and whether any terms are ambiguous, because without that it doesn't know where to get a disambiguation rule. It will take the template's structure and adapt it to your field.

06

Limitations

⚠️ Accuracy ceiling: Even with detailed context the models answered correctly in ~68% of cases, so a third of the answers were still wrong. The more complex the query (several aggregations + conditions + joins), the higher the chance of error.

⚠️ You have to write the document: A semantic layer doesn't create itself; someone has to sit down and pin down the business logic. It's one-time work, but it takes time.

⚠️ Context is advice, not law: Unlike a technical system (code, a database), an LLM in a chat receives your document as a recommendation, not a hard rule. Sometimes the model still drifts from it, especially in long prompts.

⚠️ The study is about SQL, not everything: The experiment was run on tasks that generate SQL queries against databases. The principle works for analyzing tables in a chat, but the paper has no data on other kinds of analytical tasks.

07

How They Tested It

The idea was simple: take the same 100 questions about one dataset (Contoso retail sales: 25 tables, data from 2007–2009), three models (Claude Opus 4.7, Claude Sonnet 4.6, GPT-5.4), and test each one twice. Once with the bare database schema, and once with the same schema plus 4 kilobytes of markdown explaining the business logic. Everything else was identical: same questions, same tool, same judge for scoring.

The most surprising result: the models didn't differ from each other. Without the document, all three scored 45–50% correct answers. With the document, all three hit 68%. The difference between models is statistically insignificant; the difference between conditions is huge (p ≤ 0.0015). For practitioners the message is direct: don't waste time picking a provider, spend it on the quality of your context.

The questions were deliberately hard: from simple "how many orders in January" to expert-level "calculate cohort LTV accounting for returns and the dataset's notional current date." The improvement from the document held steady across all difficulty levels, not just the easy or hard ones.

A telling detail: in a parallel Bayer study on medical data (60 questions against a pharmacovigilance database), GPT-4 without a context document scored 8.3% accuracy, and 78.3% with one. A 70-percentage-point gap. The effect isn't unique to retail; it's structural.

08

Original Text from the Paper

A semantic layer is an authoritative description of a dataset's business concepts —
the measures, dimensions, entities, and relationships that together constitute the
language in which analytical questions are asked. It is the artifact in which a data
team records decisions like "revenue means SalesAmount from the online-sales fact,
excluding canceled orders," or "region means the customer's country-continent
hierarchy, not the store's," or "inventory means the latest daily snapshot, not a
sum over time."

A well-constructed semantic layer for a given dataset typically specifies:
• Fact table selection rules — Which fact table is authoritative for which question class
• Measures and their formulas — How metrics are computed with the exact columns and aggregations
• Dimensional hierarchies and join paths — How entities relate and which keys to join on
• Data conventions and quirks — How the data actually encodes things: string-booleans,
  sentinel values, snapshot-vs-cumulative semantics, currency conventions
• Disambiguation rules — How to resolve ambiguous phrasing: whether "sales" defaults
  to online or all-channel, whether "region" refers to customer or store geography,
  whether "last quarter" is relative to today or to the dataset's latest date

Context: The authors describe exactly what goes into a semantic layer. This is their working definition from Section 3.1, which became the basis of the 4KB document used in the experiment.

09

Adaptations and Extrapolations

💡 Adaptation: A semantic layer for analyzing any document, not just data

The principle reaches beyond SQL. If you ask Claude to analyze a contract, financial statements or a technical document, give it a "glossary" for your field up front.

Task: Analyzing a supply contract with non-standard terms

Prompt add-on before the document:

## Context for the analysis

Terminology of this contract:
- "Supplier" in our context = Miller Supply LLC; we act as the "Customer"
- "Penalties" in our practice apply only after the 2nd violation; the 1st is a warning
- "Acceptance" is considered complete once both parties sign, not upon delivery
- We resolve disputes in the courts of Cook County, Illinois, even if the contract names another venue

Analyze the contract with these rules in mind.

🔧 Technique: Document the "red flags" for your data domain

Instead of (or in addition to) metric definitions, give the model a list of typical traps in your data.

## Known traps in this data
- The is_active column contains the strings 'Y'/'N', not booleans: don't filter with == True
- The orders table has duplicate rows for orders with multiple statuses: count DISTINCT order_id
- Dates in created_at are UTC+0, our sales are in UTC-5: shift by 5 hours when grouping by day
- Orders with promo code NULL and with promo code 'NONE' are different situations (NULL = no promo, 'NONE' = promo rejected)

This removes the most common class of "silent errors," where the LLM returns a syntactically correct but wrong result.


🔧 Technique: A cumulative semantic layer you update as you go

Start with a minimal document, look at where the model goes wrong, and add rules.

  1. Ask a question with a basic semantic layer
  2. Get the answer
  3. Ask: "Explain step by step how you calculated this metric"
  4. Find where it diverges from your business logic
  5. Add that rule to the document

After 5–7 iterations you'll have a document that covers most of the typical errors for your specific data.

10

Resources

Title: Semantic Layers for Reliable LLM-Powered Data Analytics: A Paired Benchmark of Accuracy and Hallucination Across Three Frontier Models

Authors: Michael Rumiantsau, Ivan Fokeev — Cube (cube.dev)

Code and data: https://github.com/cubedevinc/semantic-layer-benchmark

Dataset: Cleaned Contoso Retail Dataset — https://www.kaggle.com/datasets/bhanuthakurr/cleaned-contoso-retail-dataset

Benchmarks mentioned: BIRD (Li et al., 2023), Spider 2.0 (Lei et al., 2025), BEAVER (Chen et al., 2024), NL2SQL-Bugs (Liu et al., 2025), dbt Labs benchmark (Ganz & Perigaud, 2026), Bayer/JAMIA Open (Zargari Marandi et al., 2024)

Research digest

Key result

Is the `SalesAmount` column in your table revenue before returns or after? Is region the customer's or the warehouse's? The LLM sees a bare schema and guesses. It gets it right about half the time. The semantic layer method lets you analyze data so that the model applies your business logic instead of inventing its own. Add 1-2 pages of markdown with metric definitions before the data and the question, and accuracy jumps by 17-23 percentage points. The difference between Claude and GPT is pocket change. The difference between "with context" and "without" is huge.

Principle

A standard request gives the model two tasks at once: guess what your data means, and calculate what you asked for. It's like asking someone to solve a problem in a language they don't speak. The semantic layer splits the tasks: you do the guessing once and write it down, and the model just applies ready-made rules. "Guess the business logic from bare column names" and "take the definition from the document" are fundamentally different instructions. The first is a lottery. The second is routine.

Why it works

More than 80% of errors in LLM data analysis aren't math. The model grabs the wrong column, aggregates the wrong way, misreads a term. A data schema says what exists; a semantic layer says what it means and how to use it. The gap between "structure" and "meaning" is exactly where the model gets lost. The document closes that gap. You're not making the model smarter; you're changing the task itself.

When to apply

For any LLM analysis of tables, CSVs or databases, especially when the metrics are specific to your company: keep rate, margin, conversion, gross sales. It matters most when one term can mean two different things depending on context (for example, are "sales" orders placed or paid deliveries?). NOT a full replacement for an analytics system: even with detailed context, the models get every third complex query wrong, the ones with several conditions plus aggregations plus joins across multiple tables.

Mini recipe

1. Pick 5-7 non-obvious metrics: Choose the ones different people on your team understand differently. For each, write down what to include, what to exclude, and the formula. 2. Add table conventions: What common field values mean ('Yes'/'No', empty fields, order statuses). Where "the latest period" starts: from the maximum date in the table or from today. 3. Lock in disambiguation rules: If a term can mean two different things, write down both options and the rule for choosing. For example: "If the question says \"revenue\", use the `net_revenue` column, not `gross_revenue`." 4. Put the document before the data: Semantic layer first, then the data, then the question. Order matters: the model reads top to bottom and applies the rules to whatever comes after. 5. Quick start: Ask the LLM itself to help you draft the document. Give it the template and a description of the task, and it will ask clarifying questions about each metric.

Examples

[BAD]: `Show the top 5 managers by net revenue for the last quarter`: the model guesses what "net revenue" means (before or after fees?), what "last quarter" means (from today or from the latest date in the table?), and grabs the first column that looks right. [GOOD]: `## Semantic layer "Net revenue": the sum of the amount column minus the commission column minus returns (rows with status refunded). Do not use the revenue column: it holds gross with no deductions. "Last quarter": count back 90 days from the maximum date in the table, not from today's date. Manager: the manager_name column, not manager_id. ## Data [table or CSV] ## Question Show the top 5 managers by net revenue for the last quarter. For each: gross sales, returns, commission, final net revenue.` Result: the model applies your definitions literally and won't mix up gross with net.

In plain words

When an LLM digs into your spreadsheets, it acts like an intern on day one: lots of data, and no clue what any of it means. By default the model doesn't understand your business logic; it just sees a pile of numbers and column names. If you don't explain the rules of the game, it starts to hallucinate, inventing its own formulas for profit or conversion. The point is that models need more than "here's the data"; they need a semantic layer, essentially a glossary that translates dry table headers into actual meaning.

Picture walking into someone else's apartment and trying to cook dinner without knowing which jar is salt and which is sugar, because they're in identical unlabeled containers. You might guess right, but there's a good chance your tea ends up salty. A semantic layer is those labels on the jars. Without them even the smartest model (be it GPT-4 or Claude 3.5) turns into a fortune teller who confidently delivers total nonsense, simply because "revenue" in your head and "revenue" in its training data are two different things.

The study cleanly separated two approaches: giving the model raw data, or giving it a description of the metrics. It turned out that when you spell out that "keep rate" means delivered items divided by ordered items rather than just a unit count, analytical accuracy shoots up. Three things do the work: explicit definitions (zero ambiguity), filtering rules (which order statuses count as "live") and aggregation logic. Without this "meaning crutch," top models stumble even on simple queries, because they try to fill in context where there isn't any.

Although this was tested on business reports, the principle is universal. It applies to any work with data, from analyzing server logs to a personal habit tracker. If you ask an AI to analyze your Excel file but don't attach a "user manual" for its columns, you're nudging the model off a cliff yourself. SEO for data no longer cuts it; you need to build GEO (Generative Engine Optimization) into your own documents so the AI understands the structure of your business as well as you do.

The main takeaway is simple: stop counting on "magic" and model cleverness. If you want sensible numbers rather than creative fiction, a semantic layer is mandatory. Either you spend 10 minutes describing how your KPIs are calculated, or you get a report that looks great but is actually pure garbage. In a world where AI makes decisions, the winner is whoever best explains to the machine what their numbers actually mean.

AI lab assistant

Apply this study to your task

Describe what you're working on. AI takes the method and the measured results from this paper and adapts them to your case, or writes a ready prompt built on them.

Based on Semantic Layer: A Business-Context Document Doubles LLM Accuracy in Data Analysis arXiv:2604.25149

Sign in to apply this study New accounts get 50 free credits.