See llms.txt for all machine-readable content.

Back to Templates

File validated incident reports from Retell AI calls with Claude and Google Sheets

Quick overview

Gives a Retell AI phone agent three custom functions for an incident line: find the site and the caller the way people say them, then file a strictly checked report. Misheard names still match, every report gets a stable number, and calls that end early are rebuilt by Claude.

How it works

  1. Receives a POST webhook from Retell (custom function call or call event) and verifies the HMAC signature and timestamp.
  2. For find_site and find_person requests, reads the Sites and People tabs in Google Sheets and returns a best match or a short list for the agent to confirm (including phone-number matching when no person query is provided).
  3. For file_incident requests, validates the provided site, caller, incident type, severity, and description and returns questions to ask if anything is missing.
  4. When the incident is valid, checks the Incidents tab for an existing row for the same call ID to avoid duplicates, then appends a new incident row with a stable incident number.
  5. Emails the formatted incident details to dispatch via SMTP (and includes the on-call address for high/critical severities).
  6. When Retell sends call_analyzed for a call with no report, Claude reads the transcript, the same lookups resolve the site and the caller, and the report is saved as Needs review with a Check email to dispatch. Wrong numbers and short calls are skipped.

Setup

  1. Create a Google Sheet with three tabs named Sites, People, and Incidents (or update the tab names and column headers used for Site ID, Employee ID, and Phone).
  2. Add credentials for Google Sheets OAuth2, SMTP email, Anthropic, and Crypto (set the HMAC secret to your Retell API key).
  3. Update the spreadsheet URL/ID and email addresses (dispatch, on-call, and sender) in the workflow settings, and adjust allowed incident types, urgent severities, and match/transcript thresholds as needed.
  4. Copy the production webhook URL into Retell and configure the agent webhook plus three custom functions (find_site, find_person, file_incident) to POST to this URL.
  5. In Retell, add find_site, find_person and file_incident as custom functions (POST, Payload: args only off) with the JSON schemas from the sticky note, all pointing at this workflow's production webhook URL. Set the same URL as the agent's webhook for call events. Turn on Talk While Waiting, then activate the workflow.

Requirements

  • A Retell AI agent with custom functions, and its API key with the webhook badge.
  • Google Sheets, an SMTP account and an Anthropic API key (or another chat model for the transcript step).
  • n8n reachable from the internet for the webhook. Built on n8n 2.21, self-hosted, no community nodes.

Customization

  • Your own directory: keep one ID column per tab and set siteKeyColumn, personKeyColumn and personPhoneColumn. Every other column (name, address, city, role) is searched.
  • incidentTypes and urgentSeverities set what the agent may file and what reaches on-call. matchThreshold (default 0.85) sets how sure a lookup must be before it reads one match back.
  • Swap Email dispatch for Slack, Teams or an SMS node, or the Incidents tab for your helpdesk: the row is already built in Answer the function call.
  • Set verifySignature to false only while you test with your own requests.

Additional info

Lookups answered in 1 to 2 seconds and a filed report in about 4 seconds in our tests on a self-hosted n8n, with Talk While Waiting covering the pause. Rows are written as plain text (RAW), so a phone number or a description that starts with + or = never turns into a formula. One report per call: a second file_incident in the same call returns the first number. Both directory tabs are read on every request, so sheet edits count at once; for tens of thousands of rows, move the directory to a database node. The transcript step sends the call transcript to the chat model; remove the call_analyzed webhook in Retell if transcripts must stay in your systems.