feat: allow setting max_billed_bytes in BigQuery tools config

This will allow users to configure a limit to access in ADK tools on the charges for queries.

PiperOrigin-RevId: 831921163
This commit is contained in:
Google Team Member
2025-11-13 10:42:56 -08:00
committed by Copybara-Service
parent 22eb7e5b06
commit ffbb0b37e1
4 changed files with 72 additions and 4 deletions
+21
View File
@@ -61,6 +61,14 @@ class BigQueryToolConfig(BaseModel):
change in future versions.
"""
maximum_bytes_billed: Optional[int] = None
"""Maximum number of bytes to bill for a query.
In BigQuery on-demand pricing, charges are rounded up to the nearest MB, with
a minimum 10 MB data processed per table referenced by the query, and with a
minimum 10 MB data processed per query. So this value must be set >=10485760.
"""
max_query_result_rows: int = 50
"""Maximum number of rows to return from a query.
@@ -91,6 +99,19 @@ class BigQueryToolConfig(BaseModel):
locations, see https://cloud.google.com/bigquery/docs/locations.
"""
@field_validator('maximum_bytes_billed')
@classmethod
def validate_maximum_bytes_billed(cls, v):
"""Validate the maximum bytes billed."""
if v and v < 10_485_760:
raise ValueError(
'In BigQuery on-demand pricing, charges are rounded up to the nearest'
' MB, with a minimum 10 MB data processed per table referenced by the'
' query, and with a minimum 10 MB data processed per query. So'
' max_bytes_billed must be set >=10485760.'
)
return v
@field_validator('application_name')
@classmethod
def validate_application_name(cls, v):
+7 -4
View File
@@ -152,12 +152,15 @@ def _execute_sql(
return {"status": "SUCCESS", "dry_run_info": dry_run_job.to_api_repr()}
# Finally execute the query, fetch the result, and return it
job_config = bigquery.QueryJobConfig(
connection_properties=bq_connection_properties,
labels=bq_job_labels,
)
if settings.maximum_bytes_billed:
job_config.maximum_bytes_billed = settings.maximum_bytes_billed
row_iterator = bq_client.query_and_wait(
query,
job_config=bigquery.QueryJobConfig(
connection_properties=bq_connection_properties,
labels=bq_job_labels,
),
job_config=job_config,
project=project_id,
max_results=settings.max_query_result_rows,
)