Google Sheets Integration
promptfoo allows you to import eval test cases directly from Google Sheets. This can be done either unauthenticated (if the sheet is public) or authenticated using Google's Default Application Credentials, typically with a service account for programmatic access.
Importing Test Cases from Google Sheets
Public Sheets (Unauthenticated)
For sheets that are accessible via "anyone with the link", simply specify the share URL in your configuration:
prompts:
- prompt1.txt
- prompt2.txt
providers:
- anthropic:messages:claude-3-5-sonnet-20241022
- openai:chat:gpt-4o
tests: https://docs.google.com/spreadsheets/d/1eqFnv1vzkPvS7zG-mYsqNDwOzvSaiIAsKB3zKg9H18c/edit?usp=sharing
💡 See our example sheet for the expected format. For details on sheet structure, refer to loading assertions from CSV.
Private Sheets (Authenticated)
For private sheets, you'll need to set up Google's Default Application Credentials:
-
Install Peer Dependencies
npm install googleapis
-
Set Up Authentication
- Create a service account in Google Cloud
- Download the JSON key file
- Enable the Google Sheets API (
sheets.googleapis.com
) - Share your sheet with the service account email (
[email protected]
) with at least viewer permissions
-
Configure Credentials
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/service-account-file.json"
-
Use the Same URL Format
tests: https://docs.google.com/spreadsheets/d/1eqFnv1vzkPvS7zG-mYsqNDwOzvSaiIAsKB3zKg9H18c/edit?usp=sharing
The system will automatically use authenticated access when the sheet is not public.
Writing Evaluation Results to Google Sheets
The outputPath
parameter (--output
or -o
on the command line) supports writing evaluation results directly to Google Sheets. This requires Default Application Credentials with write access configured.
Basic Usage
prompts:
- ...
providers:
- ...
tests:
- ...
outputPath: https://docs.google.com/spreadsheets/d/1eqFnv1vzkPvS7zG-mYsqNDwOzvSaiIAsKB3zKg9H18c/edit?usp=sharing
Targeting Specific Sheets
You have two options when writing results to a Google Sheet:
-
Write to an existing sheet by including the sheet's
gid
parameter in the URL:outputPath: https://docs.google.com/spreadsheets/d/1eqFnv1vzkPvS7zG-mYsqNDwOzvSaiIAsKB3zKg9H18c/edit#gid=123456789
💡 To find a sheet's
gid
, open the sheet in your browser and look at the URL - thegid
appears after the#gid=
portion. -
Create a new sheet automatically by omitting the
gid
parameter. The system will:- Create a new sheet with a timestamp-based name (e.g., "Sheet1234567890")
- Write results to this new sheet
- Preserve existing sheets and their data
This behavior helps prevent accidental data overwrites while keeping your evaluation results organized within the same Google Sheets document.
Using Custom Providers for Model-Graded Metrics
When using Google Sheets for test cases, you can still use custom providers for model-graded metrics
like llm-rubric
or similar
. To do this, override the default LLM grader by adding a defaultTest
property to your configuration:
prompts:
- prompt1.txt
- prompt2.txt
providers:
- anthropic:messages:claude-3-5-sonnet-20241022
- openai:chat:gpt-4-mini
tests: https://docs.google.com/spreadsheets/d/1eqFnv1vzkPvS7zG-mYsqNDwOzvSaiIAsKB3zKg9H18c/edit?usp=sharing
defaultTest:
options:
provider:
text:
id: ollama:llama3.1:70b
embedding:
id: ollama:embeddings:mxbai-embed-large
For more details on customizing the LLM grader, see the model-graded metrics documentation.