TASK_LM is a powerful custom function in Sheet Workflows that enables you to run language model prompts directly from your Google Sheet. It integrates AI-generated content into your workflows by leveraging data from cells, URLs, Google Docs, and dictionary lookups while supporting multiple output formats.
=TASK_LM(prompt, model, output_mode, max_tokens, temperature, output_doc_name, celladdress, image_url)
Parameter | Data Type | Required | Description |
---|---|---|---|
prompt |
|
Required | The input prompt or template for the language model. Supports cell references, URLs, Google Docs, and dictionary lookups. |
model |
|
Required | The model name in the format
|
output_mode |
|
Optional | The format for returning results. Defaults to text output in a single cell. Options:
|
max_tokens |
|
Optional | The maximum number of tokens the model can generate. Defaults vary by model (e.g.,
|
temperature |
|
Optional | Controls output randomness (range: 0.0 to 1.0). Lower values yield more deterministic results; the default is usually
|
output_doc_name |
|
Optional | Name for the Google Doc created with the result. A hyperlink to the document is placed in the output cell. |
celladdress |
|
Optional | The cell address where the result should be placed (e.g.,
|
image_url |
|
Optional | URL of an image to include with the prompt. Only used with models that support vision capabilities. |
You can incorporate dynamic content into the prompt using template references:
Write a product description for {A2} with price {B2}
Summarize feedback from {Name} who said: {Feedback}
Analyze this webpage: {https://www.example.com|markdown}
Summarize this report: {1d-oC-6Whej0jjdknMqw6r2WmqfdSLijS}
Create a response for customer {A2} based on details: {A1:A5,B1:B5}
TASK_LM supports multiple output formats:
List mode: Returns results as a vertical list.
=TASK_LM("Generate 5 creative project names for a mobile app about pet care", "Gemini/gemini-1.5-pro", "list")
Horizontal list mode: Returns results as a horizontal list.
=TASK_LM("Generate 5 days of the week in French", "Gemini/gemini-1.5-pro", "hlist")
Dropdown mode: Creates a dropdown list with AI-generated options.
=TASK_LM("Generate 10 possible job titles for a marketing professional", "Gemini/gemini-1.5-pro", "dropdown")
Generate content that is automatically placed in a new Google Doc:
=TASK_LM("Write a 500-word short story about a detective who solves crimes using AI", "Gemini/gemini-1.5-pro", , 1000, 0.8, "Detective Story")
This call generates the story, creates a new Google Doc named "Detective Story", and places a hyperlink to the document in the output cell.
Use image analysis by including an image URL in your prompt:
=TASK_LM("Describe what is in this image in detail", "Gemini/gemini-1.5-pro", , , , , , "https://example.com/image.jpg")
This sends both the text prompt and the image to the model for integrated processing.
Write a professional email announcing a new product called "WorkflowPro".
=TASK_LM("Write a professional email announcing a new product called 'WorkflowPro'", "Gemini/gemini-1.5-pro")
Generate a birthday message using data from specific cells.
=TASK_LM("Write a birthday message for {A2} who is turning {B2} and enjoys {C2}", "OpenAI/gpt-3.5-turbo")
List 5 key strategies for improving customer retention as a vertical list.
=TASK_LM("List 5 key strategies for improving customer retention", "Gemini/gemini-1.5-pro", "list")
Generate a detailed report on renewable energy sources with a lower temperature to ensure factual accuracy.
=TASK_LM("Write a detailed report on renewable energy sources and their benefits", "Anthropic/claude-3-opus-20240229", , 2000, 0.2, "Renewable Energy Report")
Compare and contrast information from a Google Doc with data on a webpage.
=TASK_LM("Compare and contrast the information from this document {A3} with the data in this webpage {https://www.example.com|markdown}", "OpenAI/gpt-4")
Analyze a product image and suggest presentation improvements.
=TASK_LM("What are the key elements visible in this product image and how could the presentation be improved?", "Gemini/gemini-1.5-pro", , , , , , "https://example.com/product.jpg")
Generate 10 possible categories for classifying customer feedback and display them as a dropdown list.
=TASK_LM("Generate 10 possible categories for classifying customer feedback", "Gemini/gemini-1.5-pro", "dropdown")
Ensure that the function name is spelled correctly as
TASK_LM
Verify that cell references, URLs, and Doc IDs are formatted correctly and that the referenced cells contain valid data.
Check that your API key is configured correctly for the chosen provider and that you have sufficient API quota.
Confirm that the
celladdress
"C1"
Increase the
max_tokens
Consider using a faster model, simplifying your prompt, or reducing the
max_tokens
Ensure that the dictionary ranges are valid and that the keys exist within the referenced data.
TASK_LM supports a wide range of models from providers such as Gemini, OpenAI, Anthropic, and Groq. Use the
TASK_MODELS
While the Sheet Workflows add-on may require a subscription, using TASK_LM also depends on API usage from language model providers, some of which may incur charges.
API keys are configured in the Sheet Workflows sidebar under the Configuration tab. Enter your API keys for the desired providers.
The data limit depends on the model's context window, generally ranging from 4,000 to 32,000 tokens. Ensure your prompt fits within these limits.
TASK_LM returns a JSON string that must be executed using the "Run" button in the sidebar. It is not designed to be nested within other formulas.
Currently, TASK_LM supports only one image per prompt via the
image_url
No, only the
prompt
model
TASK_LM offers enhanced template capabilities, multiple output options, and the ability to create Google Docs, making it more powerful for complex workflows.
Yes, TASK_LM can be integrated into automated workflows using the automation features of Sheet Workflows.
Yes, if a cell reference points to another reference (such as a URL or a Google Doc), TASK_LM will process them recursively.
Use dictionary syntax (e.g.,
{A1:A5,B1:B5}
Empty cells are ignored when processing the template.
While there is no direct table format option, you can prompt the model to return data in a table-like format suitable for rendering in a Google Doc.
Yes, a hyperlink to the newly created Google Doc is placed in the output cell.
5 months ago
1 month ago
1 month ago