Category: General-Purpose AI Function - Table-Valued Function (TVF)
Description
Generates structured data as a table with your custom schema by calling a remote model. This table-valued function is ideal for extracting multiple structured records from unstructured text, such as extracting multiple products from a catalog description or multiple entities from a document.
Use Cases
Data Extraction: Extract multiple structured records from text
Entity Recognition: Identify and structure multiple entities from documents
List Generation: Create structured lists from narrative text
Parsing Documents: Extract tabular data from PDFs or text
Catalog Processing: Structure product information from descriptions
Syntax
AI.GENERATE_TABLE(
MODEL remote_model_name,
prompt_column_or_literal,
output_schema,[, STRUCT(param => value, ...)])
AI.GENERATE_TABLE(
MODEL remote_model_name,
prompt_column_or_literal,
output_schema,[, STRUCT(param => value, ...)])
AI.GENERATE_TABLE(
MODEL remote_model_name,
prompt_column_or_literal,
output_schema,[, STRUCT(param => value, ...)])
Parameters
MODEL: Remote model created with CREATE REMOTE MODEL
prompt: Column name or string literal containing the prompt
output_schema: TABLE defining the structure
STRUCT (optional): Model parameters like temperature, max_output_tokens
Code Examples
Example 1: Extract Product List from Description
-- Create remote model firstCREATEOR REPLACE MODEL my_dataset.gemini_model
REMOTE WITHCONNECTION `us.my_vertex_connection`
OPTIONS (endpoint = 'gemini-2.0-flash-exp');
-- Extract structured product dataSELECT
source_doc_id,
product_name,
price,
category
FROM
AI.GENERATE_TABLE(
MODEL my_dataset.gemini_model,
CONCAT('Extract all products mentioned in this text: ', product_catalog_text),TABLE<product_name string,="" price="" float64,="" category="" string="">
),
-- Create remote model firstCREATEOR REPLACE MODEL my_dataset.gemini_model
REMOTE WITHCONNECTION `us.my_vertex_connection`
OPTIONS (endpoint = 'gemini-2.0-flash-exp');
-- Extract structured product dataSELECT
source_doc_id,
product_name,
price,
category
FROM
AI.GENERATE_TABLE(
MODEL my_dataset.gemini_model,
CONCAT('Extract all products mentioned in this text: ', product_catalog_text),TABLE<product_name string,="" price="" float64,="" category="" string="">
),
-- Create remote model firstCREATEOR REPLACE MODEL my_dataset.gemini_model
REMOTE WITHCONNECTION `us.my_vertex_connection`
OPTIONS (endpoint = 'gemini-2.0-flash-exp');
-- Extract structured product dataSELECT
source_doc_id,
product_name,
price,
category
FROM
AI.GENERATE_TABLE(
MODEL my_dataset.gemini_model,
CONCAT('Extract all products mentioned in this text: ', product_catalog_text),TABLE<product_name string,="" price="" float64,="" category="" string="">
),
Example 2: Extract Contacts from Email
SELECT
email_id,
contact_name,
email_address,
phone_number,roleFROM
AI.GENERATE_TABLE(
MODEL my_dataset.gemini_model,
CONCAT('Extract all contacts mentioned in this email: ', email_body),TABLE<
contact_name STRING,
email_address STRING,
phone_number STRING,role STRING
>
),
emails
WHERE category = 'business'
SELECT
email_id,
contact_name,
email_address,
phone_number,roleFROM
AI.GENERATE_TABLE(
MODEL my_dataset.gemini_model,
CONCAT('Extract all contacts mentioned in this email: ', email_body),TABLE<
contact_name STRING,
email_address STRING,
phone_number STRING,role STRING
>
),
emails
WHERE category = 'business'
SELECT
email_id,
contact_name,
email_address,
phone_number,roleFROM
AI.GENERATE_TABLE(
MODEL my_dataset.gemini_model,
CONCAT('Extract all contacts mentioned in this email: ', email_body),TABLE<
contact_name STRING,
email_address STRING,
phone_number STRING,role STRING
>
),
emails
WHERE category = 'business'
Example 3: Parse Meeting Notes into Action Items
SELECT
meeting_id,
action_item,
assigned_to,
due_date,
priority
FROM
AI.GENERATE_TABLE(
MODEL my_dataset.gemini_model,
CONCAT('Extract all action items from these meeting notes: ', notes),TABLE<
action_item STRING,
assigned_to STRING,
due_date STRING,
priority STRING
>,
STRUCT(0.3AS temperature)),
meeting_notes
WHERE meeting_date >= CURRENT_DATE() - 7
SELECT
meeting_id,
action_item,
assigned_to,
due_date,
priority
FROM
AI.GENERATE_TABLE(
MODEL my_dataset.gemini_model,
CONCAT('Extract all action items from these meeting notes: ', notes),TABLE<
action_item STRING,
assigned_to STRING,
due_date STRING,
priority STRING
>,
STRUCT(0.3AS temperature)),
meeting_notes
WHERE meeting_date >= CURRENT_DATE() - 7
SELECT
meeting_id,
action_item,
assigned_to,
due_date,
priority
FROM
AI.GENERATE_TABLE(
MODEL my_dataset.gemini_model,
CONCAT('Extract all action items from these meeting notes: ', notes),TABLE<
action_item STRING,
assigned_to STRING,
due_date STRING,
priority STRING
>,
STRUCT(0.3AS temperature)),
meeting_notes
WHERE meeting_date >= CURRENT_DATE() - 7
Example 4: Extract Product Features
SELECT
product_id,
feature_name,
feature_value,
feature_category
FROM
AI.GENERATE_TABLE(
MODEL my_dataset.gemini_model,
CONCAT('List all features of this product: ', product_description),TABLE<
feature_name STRING,
feature_value STRING,
feature_category STRING
>
),
products
WHERE features_extracted = FALSE
SELECT
product_id,
feature_name,
feature_value,
feature_category
FROM
AI.GENERATE_TABLE(
MODEL my_dataset.gemini_model,
CONCAT('List all features of this product: ', product_description),TABLE<
feature_name STRING,
feature_value STRING,
feature_category STRING
>
),
products
WHERE features_extracted = FALSE
SELECT
product_id,
feature_name,
feature_value,
feature_category
FROM
AI.GENERATE_TABLE(
MODEL my_dataset.gemini_model,
CONCAT('List all features of this product: ', product_description),TABLE<
feature_name STRING,
feature_value STRING,
feature_category STRING
>
),
products
WHERE features_extracted = FALSE
Example 5: Extract Entities from Legal Documents
SELECT
document_id,
party_name,
party_type,
role_in_contract,
contact_info
FROM
AI.GENERATE_TABLE(
MODEL my_dataset.gemini_model,
CONCAT('Extract all parties mentioned in this contract: ', contract_text),TABLE<
party_name STRING,
party_type STRING,
role_in_contract STRING,
contact_info STRING
>,
STRUCT(0.2AS temperature,2000AS max_output_tokens
)),
SELECT
document_id,
party_name,
party_type,
role_in_contract,
contact_info
FROM
AI.GENERATE_TABLE(
MODEL my_dataset.gemini_model,
CONCAT('Extract all parties mentioned in this contract: ', contract_text),TABLE<
party_name STRING,
party_type STRING,
role_in_contract STRING,
contact_info STRING
>,
STRUCT(0.2AS temperature,2000AS max_output_tokens
)),
SELECT
document_id,
party_name,
party_type,
role_in_contract,
contact_info
FROM
AI.GENERATE_TABLE(
MODEL my_dataset.gemini_model,
CONCAT('Extract all parties mentioned in this contract: ', contract_text),TABLE<
party_name STRING,
party_type STRING,
role_in_contract STRING,
contact_info STRING
>,
STRUCT(0.2AS temperature,2000AS max_output_tokens
)),
*dbt® and dbt Core® are federally registered trademarks of dbt Labs, Inc. in the United States and various jurisdictions around the world. Paradime is not a partner of dbt Labs. All rights therein are reserved to dbt Labs. Paradime is not a product or service of or endorsed by dbt Labs, Inc.
*dbt® and dbt Core® are federally registered trademarks of dbt Labs, Inc. in the United States and various jurisdictions around the world. Paradime is not a partner of dbt Labs. All rights therein are reserved to dbt Labs. Paradime is not a product or service of or endorsed by dbt Labs, Inc.
*dbt® and dbt Core® are federally registered trademarks of dbt Labs, Inc. in the United States and various jurisdictions around the world. Paradime is not a partner of dbt Labs. All rights therein are reserved to dbt Labs. Paradime is not a product or service of or endorsed by dbt Labs, Inc.