BigQuery CLI (bq)
$ bq Official High RiskThe bq CLI ships with the Google Cloud SDK to query BigQuery datasets, inspect table schemas, and manage jobs/tables. Crucially for AI agents, bq query --dry_run estimates bytes processed before incurring scan costs, and --format=json outputs clean structured records.
brew install --cask google-cloud-sdk bq query --dry_run --format=json and bq show --schema provide exact cost estimation and schema inspection in one deterministic shell call.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Supports --format=json/prettyjson/csv, --dry_run, --maximum_bytes_billed, and non-interactive nouse_legacy_sql flags, though flag syntax uses --snake_case.
- Supports
--format=json,--dry_run, and--maximum_bytes_billed
--dry_run and --maximum_bytes_billed provide strong cost-safety guardrails; bq rm requires -f to skip confirmation.
- Built-in
--dry_runbyte estimation and--maximum_bytes_billedhard cap
Bundled inside the large google-cloud-sdk distribution rather than a standalone small binary.
- Requires full Google Cloud SDK installation and Python runtime
Unmatched for BigQuery schema inspection, dry-run cost checks, job polling, and data loading.
- Full coverage of BigQuery queries, datasets, tables, and load/extract jobs
Official Google Cloud CLI maintained by Google.
- Official Google Cloud SDK component
Comprehensive Google Cloud reference docs, though legacy vs standard SQL flags can trip newcomers.
- Official reference at cloud.google.com/bigquery/docs/reference/bq-cli-reference
Security, Auth & Guardrails
Reuses gcloud credentials in ~/.config/gcloud/ or GOOGLE_APPLICATION_CREDENTIALS service account JSON.
CLI is free with Google Cloud SDK; BigQuery queries bill per TB scanned (1 TB/month free tier) or slot reservations.
# BigQuery bq CLI Agent Rules - ALWAYS pass `--use_legacy_sql=false --format=json` and run `--dry_run` before executing queries. - Set `--maximum_bytes_billed=<bytes>` on exploratory queries to cap scan billing. - NEVER run `bq rm` on datasets or tables autonomously.
Agent-Ready Command Recipes
Safe Read-Only Queries
bq show --schema --format=prettyjson <project>:<dataset>.<table>
Retrieves column names, types, and descriptions without scanning table bytes.
--dry_run bq query --use_legacy_sql=false --dry_run --format=json 'SELECT count(*) FROM `<project>.<dataset>.<table>`'
Returns totalBytesProcessed in JSON so agents can verify cost before executing.
Controlled Writes & Previews
bq query --use_legacy_sql=false --maximum_bytes_billed=1000000000 --format=json 'SELECT * FROM `<project>.<dataset>.<table>` LIMIT 20'
Runs Standard SQL with a strict 1 GB billing guardrail cap.
Strengths for Agents
- +
--dry_runreports exacttotalBytesProcessedbefore running any query. - +
--maximum_bytes_billedenforces a hard cost ceiling per query. - +
bq show --schema --format=prettyjsoninspects schemas at zero query cost.
Caveats & Pitfalls
- ! Defaults to Legacy SQL unless
--use_legacy_sql=false(or~/.bigqueryrc) is explicitly passed. - ! Ships only as part of the heavyweight Google Cloud SDK.