Unified CLI & Standalone Agent
Datagrunt 5.8.0 expands the top-level datagrunt command into a unified, lazy-loading CLI covering tabular inspection, row sampling, read-only DuckDB SQL, format conversion, deterministic PDF extraction, schema-driven rationalization, the self-hosted MCP server, and the standalone data-engineering agent.
datagrunt --help and datagrunt --version import zero optional or heavy packages (polars, duckdb, pyarrow, mcp, pydantic, httpx, httpx2, anyio, pypdfium2). When a subcommand needs an optional extra that is not installed, Datagrunt exits cleanly with exit code 2 and the corresponding uv pip install command.
Subcommand Overview
| Subcommand | Extra Required | Purpose |
|---|---|---|
datagrunt inspect |
Core ([pdf] for PDFs) |
Inspect CSV/TSV dialect & schema, Excel sheets, Parquet metadata, or PDF/bundle stats |
datagrunt sample |
Core ([pdf] for PDFs) |
Preview bounded, paginated rows (table, json, jsonl, csv) |
datagrunt query |
Core ([pdf] for PDFs) |
Run read-only DuckDB SQL over a file (data table alias) |
datagrunt convert |
Core | Convert CSV, TSV, Excel, or Parquet to CSV, Excel, JSON, JSONL, or Parquet |
datagrunt pdf |
[pdf] (inspect-corpus works without [pdf]) |
Render Markdown, extract elements, export bundles/files, and build/inspect corpora |
datagrunt rationalize |
[pdf,rationalize] |
Schema-driven Pydantic extraction and grounding over PDFs, bundles, or corpora |
datagrunt mcp |
[mcp] ([mcp,pdf] for PDF tools) |
Alias for datagrunt-mcp (MCP Server Guide) |
datagrunt agent |
[agent] ([agent,pdf] for PDF tools) |
Alias for datagrunt-agent standalone agent (one-shot or interactive REPL) |
Tabular Inspection, Sampling, SQL & Conversion
datagrunt inspect
Inspect file format, byte size, CSV delimiter, Excel worksheet names, row counts, column names, and PDF/bundle page and element counts:
datagrunt inspect sales.csv
datagrunt inspect workbook.xlsx --sheet 1 --json
datagrunt inspect report.pdf --ocr auto --jsonOptions: --sheet (name or 0-based index), --lenient (ragged CSV rows), --ocr {auto,always,never}, --json.
datagrunt sample
Preview bounded rows with pagination, column selection, and optional header normalization:
datagrunt sample sales.csv -n 10 --normalize-columns --format table
datagrunt sample sales.csv -n 5 --offset 20 --columns region,amount --format jsonlOptions: -n / --rows (default 20), --offset (default 0), --columns (comma-separated), --sheet, --normalize-columns, --lenient, --format {table,json,jsonl,csv}.
datagrunt query
Run single-statement read-only DuckDB SQL over any CSV, TSV, Excel, Parquet, PDF, or verified PDF bundle file using the data table alias:
datagrunt query sales.csv "SELECT region, SUM(amount) AS total FROM data GROUP BY 1" --format jsonPass - as the SQL argument to read the query from stdin, and -o / --output to write results atomically to disk (use --overwrite to replace an existing file; symlink destinations are always refused):
echo "SELECT * FROM data WHERE amount > 100" | datagrunt query sales.csv - --format csv -o high_value.csvOptions: --limit (1–10,000, default 1000), --sheet, --normalize-columns, --lenient, --ocr {auto,always,never}, --format {table,json,jsonl,csv}, -o / --output, --overwrite. Truncated outputs emit a warning on stderr.
datagrunt convert
Convert between tabular formats (csv, excel, json, jsonl, parquet):
datagrunt convert sales.csv out.parquet --normalize-columns
datagrunt convert workbook.xlsx sheets.csv --all-sheetsOutput format is inferred from the destination suffix (.csv, .xlsx, .json, .jsonl, .ndjson, .parquet) or set explicitly with --format. .tsv is intentionally excluded from automatic suffix inference so commas are never silently written into a .tsv file. Options: --format, --sheet, --all-sheets, --normalize-columns, --lenient, --overwrite, --json.
PDF Extraction & Rationalization
datagrunt pdf
Expose deterministic v5 PDF workflows directly from the shell (requires [pdf], except inspect-corpus which reads corpus_manifest.json without [pdf]):
# Render Markdown (slice by page range or write atomically to disk)
datagrunt pdf markdown report.pdf --page-start 1 --page-end 3 -o report.md
# Extract structured elements (heading, paragraph, key_value, table, list, figure)
datagrunt pdf elements report.pdf --kind table --format jsonl
# Export to json, jsonl, markdown, parquet, csv, or a verified bundle directory
datagrunt pdf export report.pdf ./report_bundle --format bundle
# Build and inspect verified multi-PDF corpora
datagrunt pdf corpus ./pdfs -o ./corpus --render-pages vision_only --max-workers 4
datagrunt pdf inspect-corpus ./corpus --jsonFor pdf export, a destination without a suffix defaults to bundle; unrecognized suffixes fail with exit code 2.
datagrunt rationalize
Run schema-driven Pydantic extraction and 3-witness grounding over a PDF, verified bundle, or corpus directory (requires [pdf,rationalize]):
# schemas.py
from typing import Annotated
from pydantic import BaseModel
from datagrunt import Key
class PartMention(BaseModel):
part_number: Annotated[str, Key("part")]
description: str
quantity: intdatagrunt rationalize ./corpus \
--schema schemas.py:PartMention \
--prompt "Extract BOM parts" \
--model gemini:gemini-2.5-pro \
--vertex-project my-gcp-proj \
--vertex-location global \
-o parts.jsonlOptions: --schema (module.path:ClassName or path/to/file.py:ClassName), --prompt, --model (repeatable for multi-family consensus), --min-families (default 1), -o / --out (writes provenance JSONL via result.to_jsonl()), --cache-dir, --vertex-project (DATAGRUNT_VERTEX_PROJECT), --vertex-location (DATAGRUNT_VERTEX_LOCATION, default global), --vertex-express, --no-multimodal, --json.
Standalone Agent (datagrunt agent / datagrunt-agent)
Install the standalone pure-Python agent (built on datagrunt[mcp] with zero vendor SDKs):
uv pip install "datagrunt[agent]"
# Include [pdf] when inspecting or querying PDF files:
uv pip install "datagrunt[agent,pdf]"Run one-shot headless tasks (or omit the prompt on a TTY for an interactive multi-turn REPL):
# One-shot with in-process deterministic MCP server (default)
export OPENAI_API_KEY="..."
datagrunt agent --model openai:gpt-4o --root /data "Summarize total sales by region in sales.csv"
# Read prompt from stdin or pipe input
echo "List columns in sales.csv" | datagrunt agent --model openai:gpt-4o --root /data -
# Local tool-calling models with Ollama and persistent JSON session state
datagrunt agent --model ollama:qwen2.5:7b --root ./data --session session.jsonConnecting to Remote MCP Servers & --allow-remote-reads
Connect datagrunt agent to a self-hosted Streamable HTTP MCP server (datagrunt mcp --transport streamable-http) or a stdio MCP server, passing secret headers strictly from environment variables via --mcp-header-env:
export DATAGRUNT_AGENT_MODEL="anthropic:claude-sonnet-4-5"
export DATAGRUNT_AGENT_MCP_URL="https://mcp.example.com/mcp"
export MCP_AUTH_HEADER="Bearer $DATAGRUNT_MCP_AUTH_TOKEN"
datagrunt agent \
--mcp-header-env "Authorization=MCP_AUTH_HEADER" \
--allow-remote-reads \
--json \
--trace-out trace.json \
"Inspect Q4 files"When --allow-remote-reads (or DATAGRUNT_AGENT_ALLOW_REMOTE_READS=true) is enabled, the CLI auto-approves only Datagrunt’s 6 built-in read-only tools (list_files, inspect_file, read_sample, query_file, pdf_extract_elements, pdf_to_markdown) if the remote server’s tool annotations confirm readOnlyHint=True and destructiveHint is not True. Each tool’s definition_sha256 is pinned per (server_id, tool_name) on first approval so any mid-session tool definition mutation is refused. Use --no-allow-remote-reads to override the environment variable.
Write Approvals & Guardrails
- Non-interactive default deny: On non-interactive
stdin, write tools (convert_file,pdf_export) are denied unless both--allow-writes(registers the tools) and--approve-writes(auto-approves writes, optionally scoped with repeatable--approve-tool <name>) are passed. - Interactive TTY prompts: On a TTY with
--allow-writes, the REPL prompts for confirmation displaying the tool name, ASCII-escaped canonical arguments, definition hash, and approval hash. - Limits & outputs:
--max-steps(default20),--timeout(default300.0s),--per-request-timeout(default120.0s, max600.0s),--max-tokens,--json,--trace-out(0600atomic writes),--no-pdf,--no-tools.
Python API (DatagruntAgent)
from pathlib import Path
from pydantic import BaseModel
from datagrunt.agent import AgentConfig, DatagruntAgent, InProcessMCPTarget
from datagrunt.mcp import MCPServerConfig
class SalesSummary(BaseModel):
total_amount: float
top_region: str
config = AgentConfig(
model="openai:gpt-4o",
mcp_target=InProcessMCPTarget(MCPServerConfig(roots=(Path("./data"),))),
max_steps=15,
timeout_s=120.0,
)
with DatagruntAgent(config, output_schema=SalesSummary) as agent:
result = agent.run("Compute total sales and top region from sales.csv", session_path="session.json")
print(result.output)
print(result.sql_queries)Zero-SDK Google Cloud Vertex AI Routing
Both datagrunt rationalize and datagrunt agent support routing gemini:<model> and anthropic:<model> through Google Cloud Vertex AI with zero cloud SDK dependencies:
# Route Gemini or Claude through Vertex AI using ADC or gcloud
datagrunt agent \
--model gemini:gemini-2.5-pro \
--vertex-project my-gcp-proj \
--vertex-location global \
--root ./data \
"Summarize sales.csv"
datagrunt agent \
--model anthropic:claude-sonnet-4-6 \
--vertex-project my-gcp-proj \
--vertex-location us-east5 \
--root ./data \
"Summarize sales.csv"
# Vertex AI Express mode (gemini:<model> only) with GOOGLE_CLOUD_API_KEY / GEMINI_API_KEY / GOOGLE_API_KEY
export GOOGLE_CLOUD_API_KEY="..."
datagrunt rationalize ./corpus \
--schema schemas.py:PartMention \
--prompt "Extract BOM parts" \
--model gemini:gemini-2.5-pro \
--vertex-expressCredential resolution order for Vertex AI OAuth (--vertex-project):
google.authADC: Ifgoogle-authis installed and Application Default Credentials are configured, Datagrunt acquires and refreshes tokens in-memory under a thread lock.gcloudCLI fallback: Otherwise, Datagrunt locatesgcloudstrictly in absolute directories onPATH(never the current working directory and never withshell=True), invokesgcloud auth application-default print-access-token(falling back togcloud auth print-access-token), and caches the token in memory for 5 minutes.
Passing --vertex-express alongside --vertex-project, combining Vertex flags with --base-url, or passing --vertex-express with anthropic:<model> fails closed with a clear error. On datagrunt agent, an explicit --vertex-express flag overrides DATAGRUNT_AGENT_VERTEX_PROJECT in the environment.