Warehouses, agents, semantic layers, and MCP
contextlift decouples SQL execution (--db), SQL generation (--runner), and semantic layers (--spec, --dbt, --snowflake-semantic, --ossie, --lookml). Mix any supported warehouse, agent, and semantic source in one pipeline.
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 blocks DDL/DML, stacked statements, data-changing CTEs, and filesystem/exfiltration functions.
| Warehouse | Install extra | --db URI shape | --db-role enforcement | Status |
|---|---|---|---|---|
| SQLite | core (0 deps) | warehouse.sqlite or sqlite:///warehouse.sqlite | n/a (read-only file URI) | GA |
| DuckDB | contextlift[duckdb] | warehouse.duckdb or duckdb://warehouse.duckdb | n/a (read_only=True, locked FS) | GA |
| BigQuery | contextlift[bigquery] | bq://BILLING_PROJECT[/DATA_PROJECT.DATASET] | Refused (use IAM principal) | GA |
| PostgreSQL | contextlift[postgres] | postgresql://user:pass@host:5432/db | Enforced (SET LOCAL ROLE) | Beta |
| Snowflake | contextlift[snowflake] | snowflake://user:pass@account/db/schema?warehouse=WH | Enforced (role= connection param) | Beta |
| Databricks | contextlift[databricks] | databricks://token@host/sql/1.0/warehouses/<id>?catalog=<cat>&schema=<sch> | Refused (use scoped PAT/SP) | Beta |
Role scoping (--db-role)
Pass --db-role ROLE on Postgres (SET TRANSACTION READ ONLY + SET LOCAL ROLE) or Snowflake (role= on connect):
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 ...
BigQuery and Databricks do not support SQL session role switching from a client driver, so both executors fail closed with a clear error if --db-role is passed instead of silently ignoring it. On BigQuery, run --estimate-only before paid scoring and keep --max-bytes capped (default 1 GB).
Agent runners (--runner)
OpenAI, Anthropic, Gemini, Ollama, and vLLM
Direct HTTP runners require zero third-party LLM SDKs:
# OpenAI (OPENAI_API_KEY), Anthropic (ANTHROPIC_API_KEY), Gemini (GEMINI_API_KEY)
contextlift round --runner openai:gpt-4.1 --budget 5 --out round.json
contextlift round --runner anthropic:claude-sonnet-4-5 --budget 5 --out round.json
contextlift round --runner gemini --model gemini-2.5-flash --budget 5 --out round.json
# Local Ollama or vLLM (loopback hosts localhost, 127.0.0.1, ::1 allowed by default)
contextlift round --runner openai:qwen2.5-coder:32b --base-url http://localhost:11434/v1 --budget 1 --out round.json
For SSRF defense, HTTP 3xx redirects, cloud metadata hosts (169.254.0.0/16, metadata.google.internal), IPv6 link-local (fe80::/10), 0.0.0.0, non-canonical IP encodings, and non-loopback RFC1918 IPs (including DNS-resolved private IPs) are blocked by default. Opt in explicitly with --allow-private-endpoint only for a trusted internal VPC proxy.
Your own CLI agent (--runner command) and multi-turn clarification
Evaluate any external agent script via subprocess.run(..., shell=False) with a scrubbed subprocess environment (secrets are stripped by default; forward specific variables explicitly with --pass-env VAR):
contextlift round \
--runner command \
--command "python3 my_agent.py" \
--usd-per-call 0.01 \
--max-turns 3 \
--clarifier-cmd "python3 clarifier.py" \
--budget 5 --out round.json
For security, runner.command and clarifier_cmd inside a repo's contextlift.yaml are refused unless you pass --trust-config. Rounds record accuracy alongside turns, latency (latency_delta_ms), refusal rate, and cost telemetry in round.json, verdict.html, and pr-summary.
Offline CSV replay ($0) and Google Cloud Conversational Analytics
Already have baseline and candidate predictions? Score both CSVs (id,question,gold_sql,pred_sql) offline with zero LLM calls:
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
For Google Cloud Conversational Analytics, install contextlift[bigquery,ca] and pass --runner ca-api --project BILLING_PROJECT.
Semantic layers, Conflict Radar, and compilation
Pass your Markdown spec/ alongside any combination of dbt (--dbt), Snowflake Semantic Views (--snowflake-semantic), Apache Ossie (--ossie), and LookML (--lookml) to catch cross-layer metric and enum disagreements at $0:
contextlift lint \
--spec spec/ \
--dbt dbt_project/ \
--snowflake-semantic semantic_views/finance.yaml \
--ossie models/ossie.yaml \
--lookml looker_repo/ \
--db warehouse.duckdb
| Layer | Flag | Files read | Extra required |
|---|---|---|---|
| Markdown spec | --spec DIR | rules/*.md, schema/, authored/, vocabulary/, examples/, relationships.yaml | core (.json) or [yaml] |
| dbt | --dbt PATH | dbt_project.yml dir, schema.yml / MetricFlow YAML, and target/manifest.json | [yaml] (or core for manifest.json) |
| Snowflake Semantic View | --snowflake-semantic PATH | Semantic View YAML or JSON (tables, metrics, relationships, verified_queries) | [yaml] (or core for .json) |
| Apache Ossie | --ossie PATH | Ossie semantic model YAML or JSON | [yaml] (or core for .json) |
| LookML | --lookml PATH | LookML project directory (*.model.lkml, *.view.lkml, *.explore.lkml) | [lookml] |
Compile proven specs back into downstream semantic layers with honest certification headers (--sign-key / CONTEXTLIFT_SIGN_KEY required for signed certification; pass --require-signature to fail closed):
contextlift compile --spec spec/ --target snowflake-yaml --attestation .contextlift/attestation.json --out semantic_views/finance.yaml
contextlift compile --spec spec/ --target dbt-yaml --attestation .contextlift/attestation.json --out models/metrics.yml
contextlift compile --spec spec/ --target ossie --attestation .contextlift/attestation.json --out semantic_model.yaml
Serving certified context over MCP (serve-mcp)
Run the zero-dependency JSON-RPC 2.0 stdio server (no listening network port) exposing six tools: search_schema, get_metric, get_join_path, list_rules, lookup_verified_example, and get_attestation_status. Pass --require-signature or --require-certified in production so unverified or modified specs fail closed at startup.
Claude Code (.mcp.json)
{
"mcpServers": {
"contextlift": {
"command": "contextlift",
"args": ["serve-mcp", "--spec", "spec/", "--attestation", ".contextlift/attestation.json", "--require-signature"],
"env": {
"CONTEXTLIFT_SIGN_KEY": "${CONTEXTLIFT_SIGN_KEY}"
}
}
}
}
Cursor (.cursor/mcp.json)
{
"mcpServers": {
"contextlift": {
"command": "contextlift",
"args": ["serve-mcp", "--spec", "spec/", "--attestation", ".contextlift/attestation.json", "--require-signature"],
"env": {
"CONTEXTLIFT_SIGN_KEY": "${CONTEXTLIFT_SIGN_KEY}"
}
}
}
}
Need a custom database driver or Python agent? See Extending contextlift.