Skip to main content
The CLI is designed for programmatic use by AI agents, shell scripts, and automation pipelines. It provides structured JSON output, streaming, semantic exit codes, and dry-run capabilities for safe tool planning.

Automatic JSON Output

When stdout is not a TTY (i.e., the CLI output is piped to another command), the CLI automatically switches to JSON output. Agents and scripts get structured data without specifying --format json:

Exit Codes

The CLI uses semantic exit codes for programmatic error handling:

Exit Code Routing

Agents can branch logic based on exit codes:

Error Codes in JSON

When output is JSON, errors include a machine-readable error code:
Error codes: GENERAL_ERROR, USAGE_ERROR, CONNECTION_ERROR, QUERY_ERROR, SQL_ERROR, SECURITY_VIOLATION, AUTH_FAILURE, NOT_FOUND, TIMEOUT

NDJSON Streaming

Use --stream for newline-delimited JSON — one object per row. This is ideal for incremental processing of large result sets:

Dry Run for Planning

Agents can use --dry-run to preview SQL without executing. This is useful for query planning and validation before committing to execution:
Dry run requires no database connection, making it safe for agent planning steps.

File Output

Write results directly to a file for pipeline processing:

Watch Mode for Monitoring

Repeatedly execute a command at a fixed interval. Useful for monitoring dashboards and alerting:
Press Ctrl+C to stop.

Multi-System Workflows

Target different systems in sequence for cross-system operations:

Example: Agent Script

A complete example of an AI agent using the CLI for a text-to-SQL workflow: