Google Sheets add-on
You can call Claude in Google Sheets with the Claude for Sheets extension. Claude for Sheets enables seamless integration between Claude and Google Sheets, allowing you to execute interactions with Claude directly in cells. This tool allows for easy and rapid prompt engineering by enabling you to construct an evaluation suite and then test different prompts on every item of the evaluation suite in parallel. Separately, we have found Claude for Sheets to be excellent for a variety of office tasks such as processing and categorizing survey results, as well as analyzing tabular data found online.
Installing Claude for Sheets
Easily enable Claude for Sheets using the following steps:
-
Get your Claude API key: You will not be able to use Claude for Sheets without a developer API key. For more information on how to acquire an API key, see getting access to Claude.
-
Install the Claude for Sheets extension
- Click here to access the Claude for Sheets extension or search
Claude for Sheets
in the add-on marketplace. - Click the blue
Install
button and accept the permissions.
- Click here to access the Claude for Sheets extension or search
-
Connect your API key: Enter your API key at
Extensions
>Claude for Sheets™
>Enter your Anthropic API Key
. You may need to wait or refresh for "Enter your Anthropic API key" to appear as an option.
After you see the green 'verified' checkmark ✅ appear, Claude will be activated and ready within your Google Sheet.
You will have to re-enter your API key every time you make a new Google Sheet
Permissions
During installation, the Claude for Sheets extension will ask for a variety of permissions needed to function properly. Although the permissions requested to run Claude in Sheets are broad, please be assured that we only process the specific pieces of data that users ask Claude to run on. This data is never used to train our generative models.
Extension permissions include:
- View and manage spreadsheets that this application has been installed in - needed to run prompts and return results
- Connect to an external service - needed in order to make calls to Anthropic's API endpoints
- Allow this application to run when you are not present - needed to run cell recalculations without user intervention
- Display and run third-party web content in prompts and sidebars inside Google applications - needed to display the sidebar and post-install prompt
Cell Recalculation
You can manually recalculate
#ERROR!
,⚠ DEFERRED ⚠
or⚠ THROTTLED ⚠
cells by selecting from the recalculate options within the Claude for Sheets extension menu.
How to use Claude for Sheets
Claude functions
There are two main functions you can use to call Claude using Claude for Sheets:
1. CLAUDE()
=CLAUDE(prompt, model, params...)
CLAUDE() is the simplest way to call Claude using Claude for Sheets. To use this function, all you need is a plaintext prompt with no additional formatting. This is the function you'll probably want to use most of the time. This is identical to the Slackbot Claude interface and "Chat" mode on the Console.
Example CLAUDE() prompt
Prompt | Function format |
---|---|
In one sentence, what is good about the color blue? | =CLAUDE("In one sentence, what is good about the color blue?") |
In one sentence, what is good about the color blue? Output your answer in <answer> tags. [With parameters] | =CLAUDE("In one sentence, what is good about the color blue? Output your answer in <answer> tags.", "claude-3-opus-20240229", "temperature", 0.2, "max_tokens", 50, "stop_sequences", "[""</answer>""]", "api_key", "sk-ant-api03-j1W..." ) |
2. CLAUDEMESSAGES()
=CLAUDEMESSAGES(prompt, model, params...)
Use CLAUDEMESSAGES() to send a series of User:
and Assistant:
messages to Claude, as if you were using the Messages API. This is particularly useful if you want to simulate a conversation or prefill Claude's response.
Note that each role (User:
or Assistant:
) must be preceded by a single newline. To enter newlines in a cell, use the following key combinations:
- Mac: Cmd + Enter
- Windows: Alt + Enter
Example CLAUDEMESSAGES() prompt with prefilled assistant response
Prompt | Function format |
---|---|
User: In one sentence, what is good about the color blue? Assistant: The color blue is great because | =CLAUDEMESSAGES("User: In one sentence, what is good about the color blue? Assistant: The color blue is great because") |
Example CLAUDEMESSAGES() call with system prompt
To use a system prompt, set it as you'd set other optional function parameters. (You must first set a model name.)
=CLAUDEMESSAGES("User: Got anything to say to me? Assistant:", "claude-2.0", "system", "You are a cow who loves to moo in response to any and all user queries.")
3. [Legacy] CLAUDEFREE()
=CLAUDEFREE(prompt, model, params...)
CLAUDEFREE() allows you to call Claude as if you were using the legacy Text Completions API. To use this function, you will have to manually sandwich your prompt between \n\nHuman:
and \n\nAssistant:
as you would for a Text Completions prompt. Replace \n\n
with two actual new lines when writing your prompt in a cell.
For more information on the special "Human:"/"Assistant:" formatting in CLAUDEFREE, see our Text Completions API documentation.
Example CLAUDEFREE() prompt
Prompt | Function format |
---|---|
Human: In one sentence, what is good about the color blue? Assistant: | =CLAUDEFREE(" Human: In one sentence, what is good about the color blue? Assistant:") |
Note: This whole multiline string should go into the prompt parameter; notice also the two new lines before
Human:
.
Optional function parameters
If you want to specify API parameters, you can do so by listing argument-value pairs. For example, if you want to set the max_tokens
to 3, you can do it as follows: =CLAUDE("[your prompt]", "claude-instant-1.2", "max_tokens", 3)
.
You can set multiple parameters. Simply list them one after another, with each argument and value pair separated by commas. Note that the first two parameters must always be the prompt and the model (available models) — you cannot set an optional parameter without also setting the model.
For example, this is a valid CLAUDE function: =CLAUDE("[your prompt]", "claude-instant-1.2", "system", "[system prompt]", "max_tokens", 3, "temperature", 0.5)
The argument-value parameters you might care about most are:
max_tokens
- the total number of tokens the model outputs before it is forced to stop. For yes/no or multiple choice answers, you probably want 1-2. See our model comparisons table for the max completion length for each model.temperature
- the amount of randomness injected into results. For multiple-choice or analytical tasks, you'll want it close to 0. For idea generation, you'll want it set to 1.system
- used to specify a system prompt, which can provide context and instructions to Claude when using =CLAUDEMESSAGES() and =CLAUDE().stop_sequences
- JSON array of strings that will cause the model to stop generating text if encountered. Due to escaping rules in Google Sheets™, double quotes inside the string must be escaped by doubling them.api_key
- used to specify a particular API key with which to call Claude
Claude for Sheets guides & examples
Prompt engineering interactive tutorial
API version note
All Claude for Sheets spreadsheets linked within this section, such as the prompt engineering interactive tutorial and the prompting examples workbench, currently use the legacy CLAUDEFREE() function which calls the Text Completions API. These will be updated soon to utilize CLAUDEMESSAGES() and the Messages API.
Visit our in-depth prompt engineering interactive tutorial utilizing the Claude for Sheets add-on to learn or brush up on beginner to advanced prompt engineering techniques.
Note that just as with the rest of Claude for Sheets, you will need an API key to interact with the tutorial.
Claude for Sheets prompting examples
For example prompts, prompting structures, and Claude-powered spreadsheets, visit our Claude for Sheets prompting examples workbench. There, you can find examples for tasks such as the following:
- Longform document Q&A
- Information extraction
- Removing PII
- Customer support chatbot using FAQ
- Academic tutor
- Prompt chaining
- Function calling
- And much more!
Claude for Sheets workbook template
Make a copy of our Claude for Sheets workbook template to get started with your own Claude for Sheets work!
Troubleshooting
NAME? Error: Unknown function: 'claude'.
- Ensure that you have enabled the extension for use in the current sheet
- Go to Extensions > Add-ons > Manage add-ons
- Click on the triple dot menu at the top right corner of the Claude for Sheets extension and make sure "Use in this document" is checked
- Refresh the page
Can't enter API key
- Wait 20 seconds, then check again
- Refresh the page and wait 20 seconds again
- Uninstall and reinstall the extension
Further information
For more information regarding this extension, see the Claude for Sheets Google Workspace Marketplace overview page.
Updated about 1 month ago