Skip to main content

agentic-data-analyst

A robot detective at a desk answers a visitor's question from the bookshelf of docs and the database of data, while a second robot checks the answer and a coin jar keeps the costs

One assistant for your data and your docs: people ask in plain language and get answers they can check, at a cost you set. Numbers come from your DuckDB data through SQL that Claude writes and a second agent reviews; explanations come from your Markdown pages through a full-text search, and every page used is cited. When neither the data nor the docs hold the answer, the assistant says so instead of guessing. Deterministic guards decide what may run and what it may cost.

It runs RetroSpeedLab's Ask me anything: visitors at ask.retrospeedlab.com and /ask on Discord ask about the AI's speedruns, records, games, highscores and streams, and how the studio works. Both come from one nightly DuckDB snapshot: the lake's public tables and the docs-site and website pages, answered on a cheap model within a daily budget.

Without data tables it is a website chat: a company answers visitors from its own pages, each answer linking them.

Why

  • Self-service answers without a dashboard or a support ticket for every question, and without database access.
  • Answers you can check: every figure comes from a query you can inspect, every explanation links its page.
  • No guessing: the model answers only from what its tools returned and says when they do not hold the answer.
  • Safe by construction: one read-only, sandboxed SELECT over an allowlist of tables; the guards hold whatever the model is told.
  • Predictable cost: a cheap model, cached answers, per-person rate limits and a hard daily budget.
  • Nothing extra to host: the docs index is BM25 in the same DuckDB file as the data; no embeddings, no vector store.

Modes

The mode is part of the Domain you configure; it is never guessed from the database.

Mode Answers from Tools Example
data_and_docs Tables and pages search_docs and the data tools RetroSpeedLab's Ask me anything
docs Pages only; politely declines data questions search_docs A company website chat
data Tables only list_tables, describe_table, run_sql, show_table, show_chart An internal data desk

Use it as a library

uv add "agentic-data-analyst @ git+https://github.com/datenwissenschaften/agentic-data-analyst"

Index the pages into the DuckDB file once per snapshot, next to the data tables:

from pathlib import Path

from agentic_data_analyst import index_docs, read_pages

pages = read_pages(Path("docs-site/pages"), lambda page: f"https://docs.retrospeedlab.com/{page.with_suffix('.html').as_posix()}")
index_docs(Path("retrospeedlab.duckdb"), pages, "porter")  # the stemmer for the pages' language, e.g. "german"

Each page is split at its headings into passages with the page title, heading, URL and text. Pages built some other way go in as Page(url, markdown).

Then answer questions:

from datetime import UTC, datetime

import anthropic
from agentic_data_analyst import (
    Analyst,
    AnswerCache,
    DailyBudget,
    Domain,
    GuardedAnalyst,
    Limits,
    Models,
    RateLimit,
    connect,
    network_key,
)

domain = Domain(
    about="RetroSpeedLab, a game studio run by AI agents: an AI speedruns its own 8-bit games and humans race it",
    mode="data_and_docs",
    sql_rules="- Lower seconds are better; only won runs have a record.",
    review_rules="- times compared across games without saying so.",
)
limits = Limits(max_question_chars=300, max_model_rounds=6, max_queries=3, answer_budget_usd=0.05)
models = Models(analyst="claude-haiku-4-5", analyst_effort="low", reviewer="claude-haiku-4-5", reviewer_effort="low")
analyst = Analyst(anthropic.AsyncAnthropic(api_key="..."), connect(Path("retrospeedlab.duckdb")), models, limits, domain)

answer = await analyst.answer("How does the speedrun search work, and which game has the fastest AI record?")
# answer.text, answer.queries (SQL with rows), answer.passages (the pages it found), answer.usage, answer.complete

guarded = GuardedAnalyst(
    analyst,
    DailyBudget(Path("state/budget.json"), 2.00, limits.answer_budget_usd, lambda: datetime.now(UTC)),
    AnswerCache(500, 6 * 3600),
    burst=RateLimit("20/minute"),
    networks=RateLimit("15/hour"),
)
visitors = RateLimit("5/hour")
reply = await guarded.ask("Which game has the fastest AI record?", visitors, "web:203.0.113.7", network_key("203.0.113.7"))

A docs-only website chat indexes only its pages and sets Domain(about="...", mode="docs", sql_rules=None, review_rules=None).

Analyst.converse(history, observe) answers within a chat history and reports each step, for chat UIs.

The search uses DuckDB's fts extension. index_docs installs it; the sandboxed connection only loads it, so install it once where the app runs, e.g. at image build: python -c "import duckdb; duckdb.install_extension('fts')".

Guards

Guard What it stops Where
Question check Empty and over-long questions, before any model call check_question
Answer cache Paying twice for the same question (case and spacing ignored); only complete answers are kept AnswerCache
Rate limit One person asking too much, per asker key in a moving window RateLimit (limits)
Network limit One host rotating addresses: a limit per IPv4 /24 or IPv6 /64 network_key, GuardedAnalyst
Burst cap A flood from many askers: a limit on everyone's questions per minute GuardedAnalyst
Daily budget The total bill: released in 24 hourly shares that roll forward within the UTC day, so a flood spends only what is released; each question reserves its answer budget first, so parallel questions cannot pass the limit together; spending survives restarts DailyBudget
Rounds and queries Runaway loops: at most max_model_rounds model calls per question, docs searches included, and max_queries reviewed queries Limits
Answer budget One expensive answer: it stops before the next call once it cost more than answer_budget_usd Limits
Prices Unbounded bills: a model without a known price is refused at start Models
Mode Data tools in a docs-only chat and the docs search in a data-only one Domain
Statement Anything but exactly one SELECT (DDL, DML, COPY, ATTACH, SET, INSTALL), from DuckDB's parser check_sql
Allowlist Tables outside the file's own (the docs index included), file and system table functions, from DuckDB's syntax tree check_sql
Sandbox Writes, files, network and further extensions: read-only, enable_external_access=false, 1 GB, 2 threads, locked settings connect
Runtime Slow and huge queries: 20 s deadline, 200 rows, 8,000 characters of SQL; at most 5 passages of 2,000 characters per search run_query, search_docs

The limits count from the narrowest out (asker, network, everyone), so one asker over their own limit uses up nobody else's share. The reviewer agent catches wrong SQL; the deterministic layers keep the system safe whatever either model does. Docs searches read public pages, so they need no review. An answer may overshoot its budget by the one model round that crossed it; the daily budget books the real cost.

Flow

flowchart LR
    Q[Question] --> G{Guards}
    G -->|ok| A[Assistant]
    A -->|search_docs| P[(Pages, BM25)]
    P -->|passages with URLs| A
    A -->|list_tables / describe_table| M[(Schema only)]
    A -->|run_sql| C{Deterministic checks}
    C -->|ok| R[SQL reviewer agent]
    R -->|approved| D[(DuckDB, read-only)]
    D -->|rows| A
    A --> Ans[Answer with its queries and cited pages]

Demo chat

A Chainlit chat over a synthetic database of humans and AI agents racing five RetroSpeedLab games and two demo pages in data/docs (the levels, rules, runners and runs are invented), with tables and Plotly charts on request.

make install
cp .env.example .env   # set ANTHROPIC_API_KEY
make run               # builds data/speedruns.duckdb with the pages, then opens http://localhost:8000
make check             # ruff, strict mypy, pytest-bdd; the models are scripted, so no key is needed

Docker: docker build -t agentic-data-analyst . && docker run --rm -p 8000:8000 --env-file .env agentic-data-analyst

Layout

Module Responsibility
agent.py Analyst: prompt, tools per mode, the bounded tool loop
docs.py Pages into passages, the full-text index, search_docs
reviewer.py The SQL reviewer agent (structured output)
database.py Sandboxed connection, schema inspection, SQL checks, bounded execution
guards.py, guarded.py The guards and GuardedAnalyst, which puts them in front of an analyst
config.py, usage.py Models, Limits, Domain with its mode; token cost
charts.py Chart requests the analyst may make
app.py, figures.py, seed.py, settings.py, log.py The demo (demo extra)

Limitations

  • BM25 matches words, not meaning: a question worded unlike the pages may find nothing. The assistant then searches once more with other words, or says it does not know.
  • Prompt injection can still make the analyst write a different SELECT; the guards limit any query to reading the allowed tables within the deadline, the row cap and the budget.
  • Rate limits and the cache live in one process; run one process per database, or put both in a shared store.
  • Answer quality and injection resistance against the real models are not covered by the automated tests.

License

MIT. See LICENSE.

Metadata

Release files for agentic-data-analyst 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agentic-data-analyst 0.4.0
File Size Uploaded Provenance Actions
agentic_data_analyst-0.4.0.tar.gz 31.8 kB With provenance Details for agentic_data_analyst-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for agentic-data-analyst 0.4.0
File Interpreter ABI Platform Actions
agentic_data_analyst-0.4.0-py3-none-any.whl Python 3 none any Details for agentic_data_analyst-0.4.0-py3-none-any.whl

Total release size: 68.9 kB

Release files / agentic_data_analyst-0.4.0.tar.gz

Download URL agentic_data_analyst-0.4.0.tar.gz
Size 31.8 kB
Tags Source
SHA-256 checksum
How to use checksums
79b23c453696d9415b49b3b5941789fcbe03cb8ee6a1952b145307259aad897d
BLAKE2b-256 checksum
How to use checksums
b485d98d7e408a92978f2fdd4ed3c0a02f7fe14bd5df24d274a0f2350f6c7575
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Release files / agentic_data_analyst-0.4.0-py3-none-any.whl

Download URL agentic_data_analyst-0.4.0-py3-none-any.whl
Size 37.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5f94eb1937132b1d32fcf64c2df9f40361caf19767bf520e9e39ce01293f2a0
BLAKE2b-256 checksum
How to use checksums
71df8244d2947576f276a6a4fec5c6017de2da45257833c5cbb6ed6f217b9556
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Security for agentic-data-analyst 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for agentic_data_analyst-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page