Warehouses and agents
contextlift decouples SQL execution (--db) from SQL generation (--runner). Mix any supported warehouse with any LLM provider, local server, custom CLI agent, or offline CSV predictions.
Warehouses (--db)
Every built-in executor runs read_only_violation() before execution, enforces statement timeouts (--timeout, default 60 s) and row caps (--row-cap, default 500), and rejects DDL/DML, stacked statements, data-changing CTEs, and filesystem exfiltration functions.
| Warehouse | Install extra | --db URI shape | Status |
|---|---|---|---|
| SQLite | core (0 deps) | warehouse.sqlite or sqlite:///warehouse.sqlite | GA |
| DuckDB | contextlift[duckdb] | warehouse.duckdb or duckdb://warehouse.duckdb | GA |
| BigQuery | contextlift[bigquery] | bq://BILLING_PROJECT[/DATA_PROJECT.DATASET] | GA |
| PostgreSQL | contextlift[postgres] | postgresql://user:pass@host:5432/db | Beta |
| Snowflake | contextlift[snowflake] | snowflake://user:pass@account/db/schema?warehouse=WH | Beta |
| Databricks | contextlift[databricks] | databricks://token@host/catalog/schema?http_path=/sql/1.0/warehouses/ID | Beta |
Role scoping and row-level security (--db-role)
Pass --db-role ROLE on lint, gate, score, round, ablate, climb, triage, or ingest-failures to scope queries under a least-privilege read-only identity:
contextlift lint --spec spec/ --db "postgresql://ro@db.internal:5432/analytics" --db-role finance_ro
contextlift round --db "snowflake://svc@acct/PROD/FINANCE?warehouse=EVAL_WH" --db-role ANALYST_RO ...
- PostgreSQL: opens read-only transactions (
SET TRANSACTION READ ONLY) and issuesSET LOCAL ROLEwhen--db-roleis given. - Snowflake: passes
role=on connection and blocksCOPY INTO,PUT,GET, andCALL. - Databricks: forwards caller role metadata and restricts statements to read-only
SELECT/WITH. - DuckDB: connects with
read_only=True, setsdisabled_filesystems='LocalFileSystem', and locks configuration (lock_configuration=true). - BigQuery: dry-runs every query first (
--estimate-only) and caps scanned bytes with--max-bytes(default1 GB). Always run--estimate-onlybefore paid BigQuery scoring, then pass--budget USD.
Agent runners (--runner)
OpenAI, Anthropic, and Gemini (pure stdlib HTTP)
Direct HTTP runners require zero third-party LLM SDKs:
# OpenAI (reads OPENAI_API_KEY)
contextlift round --runner openai:gpt-4.1 --budget 5 --out round.json
# Anthropic (reads ANTHROPIC_API_KEY)
contextlift round --runner anthropic:claude-sonnet-4-5 --budget 5 --out round.json
# Gemini (reads GEMINI_API_KEY, or [gemini] extra)
contextlift round --runner gemini --model gemini-2.5-flash --budget 5 --out round.json
Local Ollama, vLLM, or self-hosted OpenAI-compatible servers
Point --base-url at any OpenAI-compatible /v1/chat/completions endpoint:
# Local loopback (localhost, 127.0.0.1, ::1) works out of the box
contextlift round \
--runner openai:qwen2.5-coder:32b \
--base-url http://localhost:11434/v1 \
--budget 1 --out round.json
For SSRF defense, cloud metadata hosts (169.254.0.0/16, metadata.google.internal), IPv6 link-local (fe80::/10), 0.0.0.0, and non-loopback RFC1918 private IPs are blocked by default. For a trusted internal VPC LLM proxy, opt in explicitly with --allow-private-endpoint.
Your own CLI or Python agent (--runner command)
Evaluate any existing agent binary, LangGraph workflow, or script without integrating an SDK. contextlift passes the question and serialized arm JSON on stdin (or template placeholders) using subprocess.run(..., shell=False):
contextlift round \
--runner command \
--command "python3 my_agent.py" \
--runner-version v2.4 \
--budget 5 --out round.json
Multi-turn clarification and Pareto efficiency
Agents that ask clarifying questions before writing SQL can be evaluated across multiple turns using --max-turns and --clarifier-cmd:
contextlift round \
--runner command \
--command "python3 my_agent.py" \
--max-turns 3 \
--clarifier-cmd "python3 clarifier.py" \
--budget 5 --out round.json
Rounds track accuracy alongside turns, latency, and token/cost telemetry so pr-summary surfaces Pareto trade-offs (accuracy vs cost per correct answer).
Offline CSV replay ($0, zero LLM calls)
Already have baseline and candidate SQL predictions from your own evaluation harness or staging logs? Feed both CSVs directly into round to get the exact same gates, holdout split, Tango intervals, verdict HTML, and signed attestation:
contextlift round \
--db warehouse.duckdb \
--spec spec/ \
--golds golds.csv \
--predictions-control arms/baseline.csv \
--predictions-treatment arms/candidate.csv \
--yes --out round.json \
--attestation-out .contextlift/attestation.json
Each prediction CSV needs id,question,gold_sql,pred_sql.
Google Cloud Conversational Analytics (ca-api)
Install contextlift[bigquery,ca] and pass --runner ca-api --project BILLING_PROJECT to evaluate Google Cloud Conversational Analytics agents with inline structured context or Knowledge Catalog delivery (--served).
Need a warehouse or agent not listed here? See Extending contextlift to plug in a custom Executor or Runner class.