7 November 2026
Tax Analytics with AI Agents: Querying DaRT Data Without SQL
Does the extract cover withholding tax? Which countries do we sell goods to? Questions like these sound simple, but they cost tax departments a lot of time, because someone first has to find out whether the data exists and where it lives. Whether a matter needs to be checked in the data or a disclosure obligation has to be met, there is usually a human translator between the tax department and the people who run the applications. And since tax-relevant data is spread across many systems (purchasing, sales, accounting, master data, web shops), that translation doesn't get any easier.
Even once it is clear where the data lives, a second translation is needed: someone has to turn the question into a query before any tax analytics can happen.
I had a feeling that AI agents could make both translations much easier, and I wanted to get a sense of how well that works in practice. So I simply tried it.
The idea
The starting point is a test extract from SAP DaRT (Data Retention Tool), SAP's tool for extracting tax-relevant data. I wrote this extract into a DuckDB database with DaRT Reader and pointed the AI agent Claude Code at it. The agent can run read-only queries against the database and search the descriptions of the DaRT segments and fields by keyword. I explain how this works technically further down.
Then I asked it three typical questions from day-to-day tax work, without any hints about tables or fields. Each answer was ready within a few seconds. I reproduce them unchanged.
Putting it to the test
Prompt: What company codes are in the extract?
The extract has one company code: 2000.
| BUKRS | Name | Country | Currency | Chart of accounts | Fiscal year variant | City |
|---|---|---|---|---|---|---|
| 2000 | Muster Handels AG | DE | EUR | SKR4 | K4 | Hamburg |
The company code table (TXW_COMPC) has only that one row. I also checked the main data tables, and every row in them has BUKRS = 2000. That covers FI document headers and items, MM documents, SD billing, G/L account balances and master data, the vendor and customer extensions, and valuation areas.
Worth noting: the agent didn't stop at the company code master. It checked whether any other company codes show up in the transaction data.
Prompt: Can you find any information about withholding tax in the extract?
The extract has withholding tax settings, but no withholding tax was applied anywhere: every withholding tax field on documents and vendors is blank or zero.
Customizing (code lists only)
-
TXW_T059Q (withholding tax codes, SAP table T059Q) has 103 codes across 15 countries. The five German ones are:
Code Description 25 Deutschland 116/25 Brutto (official code COD1) IN §48 EStG: 15 % Bauabzug Inland AU §48 EStG: 15 % Bauabzug Ausland I0 §48 EStG: Auftragsbez. Befreiung Inland A0 §48 EStG: Auftragsbez. Befreiung Ausland -
TXW_WHTTYP (withholding tax types, SAP table T059P) has 121 types across 21 countries. The two German ones are IN (§ 48 EStG Inland) and AU (§ 48 EStG Ausland). §48 EStG is the German 15 % withholding on construction services ("Bauabzugsteuer").
Company code 2000
- WT_NEWWT (extended withholding tax active) is empty, so extended withholding tax is not switched on.
Data fields (all empty)
| Table | Field(s) | Result |
|---|---|---|
| TXW_FI_POS (1,287 FI document items) | WHT code QSSKZ; WHT base, tax and exempt amounts QSSHB/QBSHB/QSFBT | Code blank on all rows; no amount other than zero |
| TXW_FI_OP (963 open items) | Same fields | Code blank on all rows; no amount other than zero |
| TXW_VENDOR (31 vendors) | WHT code QSSKZ, WHT country QLAND | Blank on all rows |
| TXW_CONDPR (868 billing pricing conditions) | WHT code MWSK2 | Blank on all rows |
None of the 31 vendors has a withholding tax code, and none of the FI documents carries a withholding tax code or amount. The extract also has no detailed withholding tax line items (SAP table WITH_ITEM), which DART would only export with extended withholding tax active.
This is where the first translation pays off: the agent clearly separates configured customizing from data that was actually posted, and names what would be missing for a real withholding tax analysis.
Prompt: What countries did we ship goods to?
We shipped goods to three countries: Germany, France and Switzerland. All 118 outbound deliveries in the extract (TXW_DL_HD, all of type J, delivery) had goods issue posted, between 12 Mar and 14 Dec 2021.
| Country | Deliveries | Ship-to customers |
|---|---|---|
| DE – Germany | 76 | 3 |
| FR – France | 37 | 3 |
| CH – Switzerland | 5 | 1 |
I took each delivery's country from its ship-to customer (KUNNR) in the customer master (TXW_CUST.LAND1). Every delivery matched a customer. There are no returns deliveries in the extract.
Checked against billing (TXW_BI_HD.LAND1): the billing documents point to the same three countries (DE 99, FR 45, CH 5), plus two documents for GB. Those two are credit memos (type G2) to customer 48, Oliver Hughes, for GBP 212.50 (Jan 2021) and GBP 347.80 (Oct 2021). They have no delivery, so nothing was shipped to the UK.
Export data: 42 deliveries have an export record (EXNUM). In the export header table (TXW_EIKP), ALAND holds the country the goods left from, not where they went: DE 103, FR 20, ES 1. So the delivery data suggests some shipments left from French or Spanish locations. The extract has no separate destination field in the export data.
The agent cross-checks deliveries against billing, spots the GB credit memos as a special case and is transparent about how it derived the countries. That is exactly what I would expect from a human colleague.
The last paragraph, however, doesn't hold up, and the numbers give it away: 42 deliveries with an export record, but 124 export records by country. That contradiction was the reason to take a closer look. It turned out that the agent had counted all records in the export header table and attributed them to the deliveries. But those records belong not only to deliveries, they also belong to billing documents and purchase orders. The French entries all come from purchase orders, so they say nothing about where our shipments left from. The conclusion that some goods were shipped from France is wrong. The answer sounds convincing, and only someone who knows the DaRT data model notices the mistake. The good news: Claude Code shows every SQL query the agent runs, so mistakes like this can be traced and the query corrected.
How I built it
DuckDB offers an extension that lets the database itself run as an MCP server (Model Context Protocol). MCP is an open protocol that AI agents such as Claude Code use to talk to external tools: they can run commands, control programs or, in this case, query databases. I use Claude Code, but the agent is interchangeable. It just has to speak MCP.
The setup is pleasantly lean, and everything runs locally on my laptop. I wrote the DaRT extract into a DuckDB database with DaRT Reader. It lives in a folder that I'll call DUCKDB_PATH below (replace this placeholder with the absolute path on your system).
Step 1: Tell the agent what's in the data
DaRT segments and fields have names like TXW_FI_POS or QSSKZ. For a language model, that doesn't mean much at first. So I also give the agent the descriptions of the segments and fields.
These descriptions are actually stored in the segments TXW_META and TXW_DIRSG2. Since DaRT Reader doesn't write TXW_DIRSG2 to the database, I created the table segment_description myself.
A macro find_fields in the file meta-macro.sql builds on this. It searches segments and fields by keyword, in either German or English, and is published to the agent as its own tool via mcp_publish_tool. If you ask the agent about withholding tax, for example, it first searches for "withholding tax", learns that the relevant fields are called QSSKZ and QSSHB and which segments they live in, and only then queries the actual data.
Show meta-macro.sql
CREATE OR REPLACE MACRO find_fields(terms, lang) AS TABLE
WITH m AS (
SELECT
segment_name,
dart_field,
sap_table,
sap_field,
CASE upper(lang) WHEN 'EN' THEN segment_desc_en
WHEN 'DE' THEN segment_desc_de END AS segment_desc,
CASE upper(lang) WHEN 'EN' THEN dart_field_desc_en
WHEN 'DE' THEN dart_field_desc_de END AS dart_field_desc
FROM segment_description
WHERE upper(lang) IN ('EN', 'DE')
)
SELECT DISTINCT *
FROM m
WHERE EXISTS (
SELECT 1
FROM unnest(string_split(terms, '|')) AS t(term)
WHERE trim(t.term) <> ''
AND ( m.dart_field_desc ILIKE '%' || trim(t.term) || '%'
OR m.segment_desc ILIKE '%' || trim(t.term) || '%')
)
ORDER BY segment_name, dart_field
LIMIT 100;
PRAGMA mcp_publish_tool(
'find_fields',
'Searches DART fields and segments by keywords in the field or segment description. Returns segment, DART field, SAP table, SAP field and descriptions in the selected language (max. 100 results).',
'SELECT * FROM find_fields($terms, $lang)',
'{
"terms": {"type": "string", "description": "Search terms separated by |, e.g. tax code|tax indicator|MWSKZ"},
"lang": {"type": "string", "enum": ["DE", "EN"], "description": "Language used for searching and for the returned descriptions: DE or EN"}
}',
'["terms", "lang"]',
'markdown'
);
Step 2: Configure the MCP server
The extension is installed once:
INSTALL duckdb_mcp FROM community;
Then I create the file mcp-init.sql in the DUCKDB_PATH folder:
-- Init script for running the DuckDB MCP server over stdio (used by Claude Code).
-- Suppress CLI result output: stdout must carry only JSON-RPC messages.
.mode trash
LOAD 'duckdb_mcp';
.read DUCKDB_PATH/meta-macro.sql
SELECT mcp_server_start('stdio', 'localhost', 0, '{
"enable_query_tool": true,
"enable_execute_tool": false,
"default_result_format": "markdown"}');
What's going on here?
.mode trashsuppresses all result output from the DuckDB command line. This matters because the agent talks to the server over standard output, and any extra output would break the protocol.LOAD 'duckdb_mcp'loads the extension..readloads the macro from step 1 and publishesfind_fieldsas a tool.mcp_server_start(...)starts the server. It is addressed over standard input and output (stdio), the agent may run read-only queries but may not modify tables, and results are returned as Markdown by default.
Step 3: Connect the agent to the server
So that the agent can find the server, I create the file duckdb-mcp.json in the same folder:
{
"mcpServers": {
"dart-duckdb": {
"type": "stdio",
"command": "/path-to-duckdb-binary",
"args": [
"-no-agent",
"-init", "DUCKDB_PATH/mcp-init.sql",
"DUCKDB_PATH/dart-db.duckdb"
]
}
}
}
command holds the path to the DuckDB command-line program. With the following command I start a Claude Code session that connects only to this MCP server:
claude --strict-mcp-config --mcp-config DUCKDB_PATH/duckdb-mcp.json
A word on data protection
The agent runs locally, but the language model usually doesn't. Query results are sent to the model provider. For real tax data, you therefore need to clarify up front which model is used under which contractual terms, or use a locally hosted model. For this post I used a test extract without any real company data.
Conclusion
With a few lines of configuration, a DaRT extract becomes a database you can query in plain language. Within seconds, the agent gives you a broad overview of the data: which segments are relevant, what is filled and what is missing. That takes a lot of the work out of the first translation.
For detailed questions, though, the export example shows that a convincing answer isn't necessarily a correct one. I take two rules from this for tax analytics with an AI agent:
- Read carefully and triangulate. Question any contradictions in the answer, like the numbers in the export example. And try to reach the same result by different routes, for example by rephrasing the question or asking the agent for a second approach.
- Determine critical numbers independently. Where an exact number matters, for example because it has to be reported, a person should write their own SQL query independently of the agent and compare the results. If they differ, the agent's SQL helps find the cause.