Skip to Content

AI Table

Overview

This function leverages an AI model (compatible with OpenAI’s API structure and supporting JSON output format) to generate structured data in the form of a table (a 2D list). It takes a prompt describing the desired table content and can optionally use header information and source data to guide the generation process.

View Python code on GitHub

Usage

Instructs an AI model to generate a table based on a prompt, optional header, and optional source data, returning the result as a 2D list.

=AI_TABLE(prompt, [header], [source], [temperature], [model], [max_tokens])

Arguments:

ArgumentTypeDescriptionDefault
promptstringThe instruction describing the table the AI should create.
header2D listOptional: A single row list defining the exact column headers for the table. If this is not specified, the model will generate its own headers.None
source2D listOptional: Source data provided to the AI to use as a basis for generating the table content. This is useful for getting the model to summarize information in a table.None
temperaturefloatOptional: Controls the randomness/creativity of the response (0.0 to 2.0). Lower values are more deterministic.0.0
modelstringOptional: The specific AI model ID to use (must support JSON mode, e.g., ‘mistral-small-2501’).mistral-small-2501
max_tokensintOptional: Maximum number of tokens for the generated table content.1500

Returns:

Return ValueTypeDescription
Table Data2D listA list of lists representing the generated table. The first row typically contains headers (unless provided via header argument). Returns [[\"Error: ...\"]] on failure.

Examples

1. Basic Table Generation

Generate a simple table listing smartphone features.

=AI_TABLE("Create a table listing the features of different smartphones including brand, model, camera quality, battery life.")

Sample Output:

BrandModelCamera QualityBattery Life
AppleiPhone 15ExcellentGood
SamsungGalaxy S24ExcellentVery Good
GooglePixel 8Very GoodGood
OnePlus12GoodExcellent

This prompt generates a table with columns for brand, model, camera quality, and battery life for various smartphones.

2. Using a Specific Header

Generate a table of tourist destinations using a predefined header.

Sample Header Data (Range A1:D1):

CountryPopular AttractionsBest Time to VisitAverage Cost
=AI_TABLE("Generate a table of top 5 tourist destinations.", A1:D1)

Sample Output:

CountryPopular AttractionsBest Time to VisitAverage Cost
FranceEiffel Tower, LouvreSpring, Fall$150/day
JapanMt. Fuji, TemplesSpring, Fall$120/day
ItalyColosseum, CanalsSpring, Summer$140/day
USAGrand Canyon, NYCSpring, Fall$160/day
ThailandBeaches, TemplesWinter$80/day

This uses the header data provided in range A1:D1 to structure the output.

3. Using Source Data

Generate a table summarizing product sales based on provided source data.

Sample Input Data (Range A1:C8):

ProductCategorySales Amount
LaptopTech1200
MouseTech25
KeyboardTech75
T-ShirtApparel20
JeansApparel50
LaptopTech1350
HoodieApparel45
=AI_TABLE("Summarize the sales data by product category.", , A1:C8)

Sample Output:

CategoryTotal SalesNumber of Items
Tech26504
Apparel1153

Assuming A1:C8 contains raw sales data, this generates a summary table based on that input.

Last updated on