The TASK_LM function runs language model operations in a cell in Google Sheets. It allows you to send prompts to various AI models, process the responses, and output the results directly to cells, as dropdown lists, or as Google Docs or text files.
=TASK_LM(header, prompt, model, [output_mode], [output_doc_name], [output_textfile_name], [celladdress], [image_url])
Parameter | Data Type | Required | Description |
---|---|---|---|
header | string | No | Column header for the task template. This appears in the first row of the output. |
prompt | string | Yes | The input prompt/template for the language model. Supports cell references {A1}, column references {A} (current row), URLs {https://example.com}, document IDs {docId}, and dictionary lookups {A1:A5,B1:B5}. |
model | string | Yes | The model name in the format 'provider/model_name' (e.g., "Gemini/gemini-1.5-pro", "OpenAI/gpt-4", "Anthropic/claude-3-5-sonnet"). |
output_mode | string | No | How to display the result: "text" (default) for text in the cell, "list" for vertical list, "hlist" for horizontal list, "dropdown" for dropdown selection, "google_doc" for Google Doc with link, "gdrive_textfile" for text file with link, "other_cell" to target a specific cell. |
output_doc_name | string | No | The name of the Google Doc to create (when output_mode="google_doc"). |
output_textfile_name | string | No | The name of the text file to create (when output_mode="gdrive_textfile"). |
celladdress | string | No | The cell address for output (e.g., "C1"). When using output_mode="other_cell", this parameter is required. Otherwise, the cell to the right of the function is used. |
image_url | string | No | The URL of an image to include with the prompt. Only works with vision-capable models. |
Include dynamic content in prompts with these placeholder formats:
{A1}
or {Sheet2!B3}
- Inserts the value of the specified cell{Url}
{A}
or {B}
- Inserts the value from the current row in the specified column by column header or column letter{https://example.com}
- Fetches and inserts web content{https://example.com|markdown}
- Fetches and formats web content{docId}
- Inserts Google Doc content{A1:A5,B1:B5}
- Creates key-value pairs from two rangesWhen using vision-capable models like Gemini or GPT-4 with vision:
image_url
parameter to a publicly accessible image URLSheetworkflows/Docs
folder in your DriveSheetworkflows/Files
folder=TASK_LM("Summary", "Summarize the quarterly results: {A2} in a concise paragraph.", "Anthropic/claude-3-5-sonnet")
=TASK_LM("Options", "Generate a list of 5 potential project names based on our product: an AI-powered spreadsheet assistant.", "OpenAI/gpt-4", "dropdown")
=TASK_LM("Meeting Notes", "Based on the agenda in cell {A} and discussion points in {B}, generate comprehensive meeting minutes in a professional format.", "Anthropic/claude-3-5-sonnet", "google_doc", "Team Meeting Minutes")
=TASK_LM("Image Analysis", "What does this chart show? What are the key trends? Provide 3 insights.", "Gemini/gemini-1.5-pro", "text", , , , "https://example.com/chart.jpg")
=TASK_LM("Python Code", "Write a Python script that analyzes stock data and generates a moving average chart.", "OpenAI/gpt-4", "gdrive_textfile", , "stock_analysis.py")
=TASK_LM("Analysis", "Analyze the sales trend: {Sales} and explain the pattern.", "Anthropic/claude-3-5-sonnet", "other_cell", , , "H5")
output_doc_name
only when needed; leave others blank with commas as placeholders{A}
references current row)Cause: The model name doesn't follow the provider/model_name format.
Solution: Use the correct format like "OpenAI/gpt-4" or "Gemini/gemini-1.5-pro".
Cause: The specified celladdress doesn't exist or is invalid.
Solution: Check the cell address format and ensure it exists in the spreadsheet.
Cause: The language model API returned an error or timed out.
Solution: Check your API configuration, internet connection, or try again later.
Cause: Placeholders in the prompt couldn't be resolved.
Solution: Ensure all referenced cells, URLs, or documents exist and are accessible.
Cause: The model didn't return a proper list format for the dropdown.
Solution: Modify your prompt to explicitly request a list of items.
To use different AI models, format the model parameter as "Provider/model-name" (e.g., "OpenAI/gpt-4", "Anthropic/claude-3-5-sonnet", "Gemini/gemini-1.5-pro"). Configure your API keys in the Sheet Workflows sidebar first.
Yes, use the syntax {A1} (cell address) to reference specific cells or {A} or {Article} (by column heading) to reference the value in the current row of column A. You can also reference ranges with {A1:A10} or create dictionaries with {A1:A5,B1:B5}.
As the model for a list of items in your prompt and use output_mode="list" for vertical lists or output_mode="hlist" for horizontal lists. The AI response will be parsed and placed in consecutive cells.
Google Sheets cells have a limit of approximately 50,000 characters. For longer outputs, use output_mode="google_doc" to create a Google Doc with the full response.
Provide a public URL to the image in the image_url parameter. This only works with vision-capable models like Gemini or GPT-4 with vision capabilities.
After entering the TASK_LM function, select the cell and click the "Run" button in the Sheet Workflows sidebar. The function itself only generates the task definition JSON.
Yes, create a template in row 1 using TASK_LM, then select multiple cells in that column and click "Run" in the sidebar. Each row will be processed using its own row-specific context.
Google Docs are stored in the "Sheetworkflows/Docs" folder and text files in the "Sheetworkflows/Files" folder in your Google Drive.
The responses are plain text or markdown by default. For formatted responses, use output_mode="google_doc" which preserves markdown formatting in the created document.
Each run creates a new document. To update content, either manually update the existing document or use TASK_APPEND with the docId of the existing document.
It works with all configured providers in Sheet Workflows, including OpenAI, Anthropic, Gemini, Groq, and others. You need to configure API keys for each provider you want to use.
Yes, use output_mode="other_cell" and specify the target cell with the celladdress parameter.
1 week ago