Skip to main content

Pydantic AI capability for chDB, the in-process ClickHouse engine: analytical SQL tools with engine-level read-only safety and typed engine errors mapped to ModelRetry.

Project description

pydantic-ai-chdb

A Pydantic AI capability for chDB, the in-process ClickHouse engine: give agents analytical SQL over local files, object storage, and remote databases — no server to start, no connection string, no credentials.

Installation

pip install pydantic-ai-chdb

Usage

from pydantic_ai import Agent
from pydantic_ai_chdb import ChDBCapability

agent = Agent(
    "openai:gpt-4o-mini",
    capabilities=[ChDBCapability(attachments={"events": "data/events.parquet"})],
)

result = agent.run_sync("What are the top 5 event types by count?")
print(result.output)

The capability registers the chDB tool suite — run_select_query (read-only ClickHouse SQL with {name:Type} parameter binding), list_databases, list_tables, describe_table, get_sample_data, list_functions, and (on writable sessions) attach_file — plus schema-first usage instructions for the system prompt. Tool names and descriptions come from the descriptors bundled with the chdb package, its single source of truth across bindings.

Typed errors become retries

The capability's on_tool_execute_error hook maps typed chdb.agents.errors.ChDBError failures to ModelRetry, so the model sees the engine's error type, code, and message —

chDB UNKNOWN_IDENTIFIER (code 47): Unknown expression identifier `SELEC` ...

— and corrects the query within the agent's retry budget instead of the run dying on an exception. Non-chDB errors propagate unchanged.

Safety defaults

  • Read-only by default. Sessions are locked with the ClickHouse readonly=2 setting: INSERT/CREATE/ALTER/DROP are rejected by the engine while SELECT and the file()/s3()/url() table functions keep working. Pass read_only=False for a writable session (this also exposes attach_file).
  • Capped results. max_rows (default 1000) and max_bytes (default 1 MB) bound every payload; truncated results carry a truncated flag. max_execution_time adds an engine-side wall-clock limit.
  • Optional source allowlist. With file_allowlist=["/data/"], file-like sources may only read under the listed prefixes and DSN-based sources (postgresql(), mysql(), remote(), …) are refused.

Sharing and lifecycle

To control the engine's lifecycle yourself — or to share one session across capabilities and other chDB bindings — create it explicitly and inject it:

from chdb.agents import ChDBTool
from pydantic_ai_chdb import ChDBCapability

engine = ChDBTool("analytics_dir", read_only=False)
capability = ChDBCapability(engine=engine)
...
engine.close()

capability.close() closes only an engine the capability created itself.

Spec-based construction works out of the box: ChDBCapability.from_spec(path="analytics_dir", read_only=True).

Requires Pydantic AI V2. This package is maintained by the chDB team.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_ai_chdb-0.1.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_ai_chdb-0.1.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_ai_chdb-0.1.0.tar.gz.

File metadata

  • Download URL: pydantic_ai_chdb-0.1.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pydantic_ai_chdb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d4fd8c3ce5d3d10bf2483e7e2ae03eeaa3b2db35a8d2a8c44746c4a3187ace19
MD5 5535221a8dc3e76cac01164d74344014
BLAKE2b-256 a3e7ee15b34a6a5f1943522d6e2a5e8face2b6a2ce024df9259703e67257ebf7

See more details on using hashes here.

File details

Details for the file pydantic_ai_chdb-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pydantic_ai_chdb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pydantic_ai_chdb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39e96cc50d7f93c2382692060f9f4898be37b9667872d9c47b8fcfcfdf5bd7fe
MD5 3d60614ec54dde043dca3b9cc11069ef
BLAKE2b-256 6ee132dad644417c93232914ac63dd197299e6c022489f39acad255fcb9a69e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page