Datagrunt 5.8.0: Unified CLI and Zero-SDK Vertex AI Routing
Datagrunt 5.8.0 is now available! This minor release expands the top-level datagrunt command into a unified, lazy-loaded CLI spanning tabular data, DuckDB SQL, deterministic PDF workflows, schema-driven rationalization, the self-hosted MCP server, and the standalone agent — alongside zero-SDK Google Cloud Vertex AI credential resolution and hardened remote read-tool auto-approvals (PR #531).
Highlights in Datagrunt 5.8.0
- Unified
datagruntCLI with Eight Subcommands (datagrunt.cli) — Introducesinspect,sample,query,convert,pdf, andrationalizealongsidemcpandagent, while keepingdatagrunt --helpanddatagrunt --versioncompletely free of eager optional or heavy imports (polars,duckdb,pyarrow,mcp,pydantic,httpx,httpx2,anyio,pypdfium2). - Deterministic Local Tabular & DuckDB SQL Subcommands — Reuses
datagrunt.mcp.toolsandPathSandboxunder local CLI defaults (1 GiBmax_file_bytes, Parquet/XLSX bomb guards, read-only DuckDB SQL, atomicos.O_NOFOLLOWfile writes, and symlink destination refusal). - CLI PDF Extraction & Schema-Driven Rationalization — Adds
datagrunt pdf(markdown,elements,export,corpus,inspect-corpus) anddatagrunt rationalizewith dynamic Pydantic schema loading (module.path:ClassNameorpath/to/schema.py:ClassName) and multi-family consensus support. - Shared Zero-SDK Google Cloud Vertex AI Auth (
_vertex_auth) — Routesgemini:<model>andanthropic:<model>through Vertex AI (--vertex-project,--vertex-location) or Vertex Express (--vertex-expressfor Gemini) across bothdatagrunt rationalizeanddatagrunt agent, resolving tokens viagoogle.authADC or a trustedgcloudbinary on absolutePATHdirectories. - Hardened
--allow-remote-readsfordatagrunt agent— Allowsdatagrunt agent(anddatagrunt-agent) to auto-approve Datagrunt’s 6 built-in read-only tools on remote MCP servers only when server annotations confirmreadOnlyHint=True(and notdestructiveHint=True) anddefinition_sha256stays pinned for the session.
1. Unified Lazy-Loaded datagrunt CLI
Running datagrunt --help or datagrunt --version dispatches solely through datagrunt.cli:main without importing polars, duckdb, pyarrow, mcp, pydantic, httpx, httpx2, anyio, or pypdfium2. If you invoke a subcommand whose optional extra is missing (such as datagrunt rationalize without [pdf,rationalize]), the CLI exits cleanly with exit code 2 and prints the exact uv pip install command.
# Inspect CSV/TSV (delimiter, schema), Excel (sheets), Parquet, or PDF metadata
datagrunt inspect sales.csv
datagrunt inspect workbook.xlsx --sheet 1 --json
# Preview bounded tabular rows (table, json, jsonl, csv)
datagrunt sample sales.csv -n 10 --normalize-columns --format table
# Run read-only DuckDB SQL over any CSV, Excel, Parquet, or PDF file (table alias: data)
datagrunt query sales.csv "SELECT region, SUM(amount) AS total FROM data GROUP BY 1" --format json
# Convert CSV, TSV, Excel, or Parquet files to CSV, Excel, JSON, JSONL, or Parquet
datagrunt convert sales.csv out.parquet --normalize-columns
datagrunt convert workbook.xlsx sheets.csv --all-sheetsKey safety and ergonomics behaviors built into datagrunt._cli_data:
- Read-only DuckDB SQL & stdin queries:
datagrunt queryaccepts-to read SQL fromstdin, enforces--limitbetween1and10,000(exiting2outside bounds), warns onstderrwhen output is truncated, and delegates to the hardened single-statement DuckDB executor. - Safe atomic writes & symlink refusal: Writing via
query -o,pdf markdown -o,convert, orpdf exportresolves only the parent directory, refuses symlinked output destinations (even with--overwrite), writes atomically through anO_NOFOLLOWtemp file withfsync+os.replace, and preserves existing POSIX file permissions on--overwrite. - No silent
.tsvdelimiter mismatches:datagrunt convertintentionally excludes.tsvfrom output extension inference so comma-delimited CSV is never silently written to a.tsvpath without an explicit--format.
You can also invoke the dispatcher programmatically in Python via datagrunt.cli.main:
import io
from datagrunt.cli import main
stdout = io.StringIO()
stderr = io.StringIO()
exit_code = main(["--version"], stdout=stdout, stderr=stderr)
print(exit_code, stdout.getvalue().strip())2. datagrunt pdf & datagrunt rationalize
All deterministic v5 PDF capabilities and schema-driven rationalization are now first-class CLI commands:
# PDF extraction, Markdown rendering, bundles, and corpora (requires [pdf])
datagrunt pdf markdown report.pdf -o report.md
datagrunt pdf elements report.pdf --kind table --format jsonl
datagrunt pdf export report.pdf ./report_bundle --format bundle
datagrunt pdf corpus ./pdfs -o ./corpus --render-pages vision_only
datagrunt pdf inspect-corpus ./corpus --jsonFor schema-driven extraction with datagrunt rationalize (requires [pdf,rationalize]), point --schema at either an importable module.path:ClassName or a standalone path/to/schema.py:ClassName file defining a Pydantic BaseModel subclass:
# 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: int# Schema-driven PDF rationalization with repeatable --model flags for multi-family consensus
datagrunt 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.jsonl_load_schema_class() registers file-based schema modules in sys.modules before execution and runs model_rebuild() so schemas using from __future__ import annotations and forward references resolve cleanly. Passing --out (-o) writes full provenance JSONL via result.to_jsonl(), while omitting -o or passing --json prints the structured summary, extracted records, and result.telemetry.to_dict() to stdout.
3. Zero-SDK Google Cloud Vertex AI Auth & Express Mode
Datagrunt 5.8.0 introduces a shared credential and target resolver (datagrunt._llm._vertex_auth) used by both datagrunt rationalize and datagrunt agent (datagrunt-agent) — with zero vendor SDK dependencies:
# Route Gemini or Claude through Google Cloud Vertex AI directly from the CLI
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"When --vertex-project (or DATAGRUNT_VERTEX_PROJECT / DATAGRUNT_AGENT_VERTEX_PROJECT) is set, credentials resolve automatically in two steps:
google.authADC (if installed): Obtains Application Default Credentials for thecloud-platformscope and refreshes expired tokens under athreading.Lock.gcloudCLI fallback: Ifgoogle-authis unavailable or unconfigured, 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 tokens in memory for 5 minutes.
For Gemini models using Vertex AI Express mode, pass --vertex-express alongside GOOGLE_CLOUD_API_KEY, GEMINI_API_KEY, or GOOGLE_API_KEY. Invalid combinations — such as pairing --vertex-project with --vertex-express, combining Vertex flags with --base-url, or passing --vertex-express with anthropic:<model> or openai:<model> — fail closed with explicit validation errors. On datagrunt agent, an explicit --vertex-express flag overrides DATAGRUNT_AGENT_VERTEX_PROJECT cleanly.
4. Hardened --allow-remote-reads for datagrunt agent
When connecting datagrunt agent to a self-hosted remote Streamable HTTP MCP server, remote tools previously defaulted to requiring interactive or --approve-writes confirmation because only the in-process server’s tool definitions are allowlisted by default.
Datagrunt 5.8.0 adds --allow-remote-reads (and --no-allow-remote-reads / DATAGRUNT_AGENT_ALLOW_REMOTE_READS) backed by ApprovalRequest.raw_annotations in datagrunt.agent.security and datagrunt.agent.loop:
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"Remote auto-approval enforces three invariants simultaneously:
- The tool name must be one of Datagrunt’s 6 built-in read-only tools (
BUILTIN_DATAGRUNT_READ_TOOLS:list_files,inspect_file,read_sample,query_file,pdf_extract_elements,pdf_to_markdown). - Remote server annotations must explicitly confirm
readOnlyHint=Trueand must not setdestructiveHint=True. - The tool’s
definition_sha256is pinned per(server_id, tool_name)on first approval — if the remote server mutates a tool definition mid-session, auto-approval is refused.
You can also configure and run DatagruntAgent directly in Python:
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")
print(result.output)Getting Started with Datagrunt 5.8.0
Install or upgrade with uv:
# Core library + unified tabular CLI (inspect, sample, query, convert)
uv pip install --upgrade datagrunt
# Add deterministic PDF CLI & Python APIs
uv pip install --upgrade "datagrunt[pdf]"
# Add schema-driven PDF rationalization
uv pip install --upgrade "datagrunt[pdf,rationalize]"
# Add the self-hosted MCP server or standalone agent
uv pip install --upgrade "datagrunt[mcp,pdf]"
uv pip install --upgrade "datagrunt[agent,pdf]"Or with pip:
pip install --upgrade datagruntExplore the new Unified CLI & Standalone Agent Guide and the MCP Server Guide for complete flag tables, environment variables, and security defaults.