# BigQuery

Source: https://docs.autessa.com/docs/tools/bigquery

> Tool types for the BigQuery connector.

# BigQuery

Tool types for querying Google BigQuery: browse datasets and tables, inspect schemas, and run SQL with built-in cost controls.

Every type on this page requires a [BigQuery connector](/docs/guide/connectors.md) (the same Google connector used for Google Analytics); `connectorId` is the ID of that connector. Each tool also names an explicit GCP `projectId`, since one connected account can span many projects. The three browse tools exist so an agent can discover schema before writing SQL — a `RUN_QUERY`-only agent tends to guess table names.

## List datasets **TOOL** `BIGQUERY_LIST_DATASETS`

Lists the datasets in a GCP project, up to `maxResults` (default 100). This is the top of the discovery chain: dataset → tables → schema → query.

### Example

```json title="Tool config"
{
  "toolType": "BIGQUERY_LIST_DATASETS",
  "connectorId": "V1StGXR8Z5",
  "projectId": "acme-analytics-prod",
  "maxResults": 100
}
```

> This tool type requires a connected external account. Pass the connector's ID as `connectorId` in the tool configuration.

**Configuration fields**

- `connectorId` (string (ID)) — The connector ID for the Google Analytics/BigQuery connection References a connector by ID.
- `projectId` (string) — The GCP project ID containing the datasets
- `maxResults` (integer) — Maximum number of datasets to return (default 100, max 1000)

## List tables **TOOL** `BIGQUERY_LIST_TABLES`

Lists the tables (and views) inside a dataset, up to `maxResults` (default 100). GA4 BigQuery exports show up here as date-sharded `events_YYYYMMDD` tables — useful context when an agent is deciding what to query.

### Example

```json title="Tool config"
{
  "toolType": "BIGQUERY_LIST_TABLES",
  "connectorId": "V1StGXR8Z5",
  "projectId": "acme-analytics-prod",
  "datasetId": "analytics_123456789",
  "maxResults": 100
}
```

> This tool type requires a connected external account. Pass the connector's ID as `connectorId` in the tool configuration.

**Configuration fields**

- `connectorId` (string (ID)) — The connector ID for the Google Analytics/BigQuery connection References a connector by ID.
- `projectId` (string) — The GCP project ID
- `datasetId` (string) — The dataset ID to list tables from
- `maxResults` (integer) — Maximum number of tables to return (default 100, max 1000)

## Get table schema **TOOL** `BIGQUERY_GET_TABLE_SCHEMA`

Returns a table's schema — column names, types, modes, and nested record structure. Have the agent call this before writing SQL against an unfamiliar table; it is the difference between correct queries and column-name guesswork.

### Example

```json title="Tool config"
{
  "toolType": "BIGQUERY_GET_TABLE_SCHEMA",
  "connectorId": "V1StGXR8Z5",
  "projectId": "acme-analytics-prod",
  "datasetId": "analytics_123456789",
  "tableId": "@@{tableId}"
}
```

> This tool type requires a connected external account. Pass the connector's ID as `connectorId` in the tool configuration.

**Configuration fields**

- `connectorId` (string (ID)) — The connector ID for the Google Analytics/BigQuery connection References a connector by ID.
- `projectId` (string) — The GCP project ID
- `datasetId` (string) — The dataset ID containing the table
- `tableId` (string) — The table ID to get schema for

## Run query **TOOL** `BIGQUERY_RUN_QUERY`

Executes SQL (Standard SQL unless `useLegacySql` is true) and returns up to `maxRows` rows (default 1000, max 10000). Two guardrails matter for cost: `maxBytesProcessed` makes the query fail fast if it would scan more data than you allow, and `dryRun: true` returns the estimated bytes scanned without executing at all — a cheap way to validate a query before paying for it. `timeoutMs` caps execution at up to 5 minutes.

### Example

```json title="Tool config"
{
  "toolType": "BIGQUERY_RUN_QUERY",
  "connectorId": "V1StGXR8Z5",
  "projectId": "acme-analytics-prod",
  "query": "@@{sqlQuery}",
  "maxRows": 1000,
  "timeoutMs": 30000,
  "maxBytesProcessed": 1000000000,
  "dryRun": false,
  "useLegacySql": false
}
```

> This tool type requires a connected external account. Pass the connector's ID as `connectorId` in the tool configuration.

**Configuration fields**

- `connectorId` (string (ID)) — The connector ID for the Google Analytics/BigQuery connection References a connector by ID.
- `projectId` (string) — The GCP project ID to run the query in
- `query` (string) — The SQL query to execute (Standard SQL by default)
- `maxRows` (integer) — Maximum number of rows to return (default 1000, max 10000)
- `timeoutMs` (integer) — Query timeout in milliseconds (default 30000, max 300000 = 5 min)
- `maxBytesProcessed` (integer) — Maximum bytes the query can process (fails if exceeded, good for cost control)
- `dryRun` (boolean) — If true, only estimates cost without executing (returns bytesProcessed estimate)
- `useLegacySql` (boolean) — If true, uses legacy SQL. Default false = Standard SQL

## Related

- [Connectors](/docs/guide/connectors.md)
- [Tools guide](/docs/guide/agentic/tools.md)
- [Google Analytics](/docs/tools/google-analytics.md)
- [AutessaDB tools](/docs/tools/autessadb.md)

