• Home
  • Google Cloud
  • Turn unstructured data into structured SQL insights with BigQuery AI.AGG (now GA)

Since we first introduced AI.AGG() in Preview, data teams have used it to synthesize millions of rows of unstructured text and multimodal data directly in SQL, from distilling product feedback to investigating application logs.

The AI.AGG() function in BigQuery recently reached general availability (GA). Alongside the GA release, we also rolled out one of the most requested capabilities from our preview users: custom structured output support. Combined with BigQuery’s new token-based cost management controls, you can now build predictable, production-ready semantic aggregation pipelines straight from SQL.

Moving from free-form text to structured outputs

Using Gemini models, AI.AGG() brings SQL aggregation to unstructured text and multimodal data. You can pass natural language instructions to AI.AGG() to synthesize thousands or even millions of rows per group, all without writing custom application pipelines or hitting model context window limits. If you want a closer look at how BigQuery handles multi-level aggregation across massive datasets under the hood, read our deep dive into the BigQuery AI.AGG() function.

During Preview, AI.AGG() returned a paragraph summary for each group. This works well when a human analyst is reading query results in the console. However, teams building automated data pipelines, downstream SQL joins, or business intelligence dashboards need structured fields that they can filter, unnest, and chart.

The new output_schema parameter solves this directly. Instead of returning a block of free-form text, BigQuery automatically formats the model’s response to match the exact structure you define, returning neatly organized fields like text, numbers, booleans, or lists that are ready to query right away.

What you can build with AI.AGG() and structured output

Getting structured results directly from AI.AGG() unlocks new workflows for analytics and engineering teams:

  • Automated bug and ticket deduplication: Group thousands of incoming bug reports or support tickets to automatically identify duplicate clusters, severity levels, and issue counts, a pattern already used internally at Google.

  • Dashboard-ready feedback analysis: Aggregate written customer reviews, voice survey recordings, or support call audio by product category to extract top recurring themes, mention counts, and standardized sentiment labels that feed straight into dashboards.

  • AI agent and chatbot quality monitoring: Analyze thousands of customer support chat transcripts to extract top failure scenarios, resolution rates, and suggested prompt or knowledge-base fixes.

  • Application log and incident triage: Summarize bursts of error logs by service or time window into structured root-cause hypotheses, affected components, and recommended next steps for on-call engineers.

  • E-commerce catalog and multimodal analysis: Group product images and descriptions by brand or category to extract common visual attributes, missing metadata tags, or quality issues across your inventory.

Seeing AI.AGG() with structured output in action

Let’s look at how the output_schema parameter works in practice. In our previous deep dive blog, we used AI.AGG() to analyze unstructured Apache Spark INFO logs grouped by Component, which returned a free-form text summary of each component’s behavior and anomalies.

1 - Results without structured output

Without output_schema, AI.AGG() returns a narrative block of text for each group.

By adding output_schema to that same query, we can turn those free-form summaries into structured data ready for downstream dashboards or alerting. Here, output_schema instructs AI.AGG() to return a description of the component’s normal operation alongside an issues array, capturing a concise summary of each detected problem (issue_desc) and how many times it occurred (occurrences):

code_block
‘gemini-4-argon’,rn output_schema=>”description STRING NOT NULL OPTIONS (description=’Description of the normal operation of the component’), issues ARRAY<STRUCT>”rn ) AS performance_analysisrnFROMrn `bq_logs_demo.spark_logs_unstructured`rnGROUP BYrn ComponentrnORDER BYrn log_count DESC;’), (‘language’, ”), (‘caption’, )])]>

You can see how the results are now neatly organized into nested STRUCT and ARRAY columns, allowing a single component like python.PythonRunner to list multiple distinct issues with their exact occurrence counts:

2 - Results with structured output

With output_schema, AI.AGG() outputs strongly typed STRUCT and ARRAY fields that can be filtered, unnested, and charted directly.

Best practices for maximizing result quality

As you design queries with AI.AGG() and output_schema, keep these four best practices in mind:

  • Mark required fields so nothing is left blank: Include NOT NULL on fields in your output_schema unless missing values are acceptable. This makes sure the model always fills in every field, preventing unexpected NULLs in your downstream queries or dashboards.

  • Include a quick example in your prompt: Giving the model a short example of what a good answer looks like (for instance, “issues”: [{“issue_desc”: “Stage 24 shows a significant backlog of tasks due to high CPU usage”, “occurrences”: 164}] in the query above) helps guide the level of detail and tone of the results.

  • Keep field formatting rules in the schema description: Instead of crowding your main prompt with formatting instructions for individual columns, attach OPTIONS(description = '...') directly to each field in your output_schema. This keeps your main prompt focused on the big-picture question while clearly telling the model what values or format you expect for each field.

  • Set a limit when asking for lists: AI.AGG() caps each group’s response at 10,000 tokens. When returning a list, ask for a specific number of items in your prompt, such as “Summarize the top 3 recurring themes” or “List the top 5 root causes,” so the response stays concise and never hits the token limit.

Get started today

With AI.AGG() now in GA, new support for structured outputs, and token-based quotas for cost management, you have everything you need to run AI-powered aggregations reliably in production.

To start building with AI.AGG(), check out these resources:

Author: wp_admin -
This post was originally published on this site
Share this post

Subscribe to our newsletter

Keep up with the latest blog posts by staying updated. No spamming: we promise.
By clicking Sign Up you’re confirming that you agree with our Terms and Conditions.

Related posts

☎
New Educronix Product

Educronix Softphone

Free WebRTC desktop softphone for Windows and macOS. Connects directly to your PBX — voice and video calls, Call Waiting, DND, live call quality and more. Choose your edition and platform:

100% WebRTC — built on the JsSIP library.

Standard Edition
Call Center Edition
🎙 AI Assistant(voice)