{"slug": "turn-unstructured-data-into-structured-sql-insights-with-bigquery-ai-agg-now-ga", "title": "Turn unstructured data into structured SQL insights with BigQuery AI.AGG (now GA)", "summary": "Google Cloud's BigQuery AI.AGG() function reached general availability, adding a custom output_schema parameter that formats Gemini model responses into structured fields such as text, numbers, booleans and lists instead of free-form paragraph summaries. The function lets data teams synthesize thousands to millions of rows of unstructured text and multimodal data per group directly in SQL, and Google said the structured output supports workflows including automated bug and ticket deduplication, dashboard-ready feedback analysis, AI agent and chatbot quality monitoring, log triage and e-commerce catalog analysis. Google paired the GA release with BigQuery's new token-based cost management controls for building predictable production semantic aggregation pipelines.", "body_md": "Since we [first introduced `AI.AGG()` in Preview](https://cloud.google.com/blog/products/data-analytics/deep-dive-into-bigquery-ai-agg-function), 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.\n\nThe  [function](https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-ai-agg) 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](https://cloud.google.com/blog/products/data-analytics/using-bigquerys-generative-ai-cost-management-features), you can now build predictable, production-ready semantic aggregation pipelines straight from SQL.\n\nUsing 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](https://cloud.google.com/blog/products/data-analytics/deep-dive-into-bigquery-ai-agg-function).\n\nDuring 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.\n\nThe 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.\n\n`AI.AGG()` and structured output\nGetting structured results directly from `AI.AGG()` unlocks new workflows for analytics and engineering teams:\n\n**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.\n\n**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.\n\n**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.\n\n**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.\n\n**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.\n\nLet's look at how the `output_schema` parameter works in practice. In our [previous deep dive blog](https://cloud.google.com/blog/products/data-analytics/deep-dive-into-bigquery-ai-agg-function), 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.\n\nBy 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`):\n\nYou 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:\n\nAs you design queries with `AI.AGG()` and `output_schema`, keep these four best practices in mind:\n\n**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 `NULL` s in your downstream queries or dashboards.\n\n**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.\n\n**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.\n\n**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.\n\nWith `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.\n\nTo start building with `AI.AGG()`, check out these resources:\n\nExplore the syntax and examples in the [official documentation for `AI.AGG()`](https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-ai-agg).\n\nRead the [deep dive into the BigQuery `AI.AGG()` function](https://cloud.google.com/blog/products/data-analytics/deep-dive-into-bigquery-ai-agg-function) for architectural background and multi-level aggregation details.\n\nLearn how to set project-level and user-level token guardrails in [Using BigQuery's generative AI cost management features](https://cloud.google.com/blog/products/data-analytics/using-bigquerys-generative-ai-cost-management-features).", "url": "https://wpnews.pro/news/turn-unstructured-data-into-structured-sql-insights-with-bigquery-ai-agg-now-ga", "canonical_source": "https://cloud.google.com/blog/products/data-analytics/extract-structured-insights-from-across-entire-tables-of-unstructured-data-with-bigquery-ai/", "published_at": "2026-12-01 17:00:00+00:00", "updated_at": "2026-12-01 17:14:34.991994+00:00", "lang": "en", "topics": ["ai-products", "large-language-models", "generative-ai", "ai-tools", "structured-data"], "entities": ["Google Cloud", "BigQuery", "AI.AGG()", "Gemini", "Apache Spark"], "also_reported_by": [], "takeaway": "Adding the output_schema parameter to BigQuery AI.AGG() makes Gemini return typed fields (text, numbers, booleans, lists) per group instead of free-form summaries, so results can be filtered, unnested and charted in downstream SQL and dashboards.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/turn-unstructured-data-into-structured-sql-insights-with-bigquery-ai-agg-now-ga", "markdown": "https://wpnews.pro/news/turn-unstructured-data-into-structured-sql-insights-with-bigquery-ai-agg-now-ga.md", "text": "https://wpnews.pro/news/turn-unstructured-data-into-structured-sql-insights-with-bigquery-ai-agg-now-ga.txt", "jsonld": "https://wpnews.pro/news/turn-unstructured-data-into-structured-sql-insights-with-bigquery-ai-agg-now-ga.jsonld"}}