Quick overview
This workflow exposes a POST webhook that cleans and normalizes messy inbound records with Google Gemini, validates the result against strict formatting rules, and then either upserts valid data into Google Sheets or quarantines failures and returns an HTTP 422 response.
How it works
- Receives a JSON record via a POST webhook endpoint.
- Defines the target field schema and cleaning rules to apply to the incoming data.
- Uses Google Gemini to transform the raw record into minified JSON that matches the target schema.
- Validates the Gemini output by parsing JSON and checking required fields plus email, E.164 phone, and YYYY-MM-DD date formats.
- If validation fails, sends the previous output and the specific validation errors back to Google Gemini for a second repair pass and validates again.
- Upserts valid records into a Google Sheets tab (using email as the key) and returns the cleaned JSON to the caller.
- Appends records that still fail after two attempts to a Google Sheets Quarantine tab and returns an HTTP 422 rejection response.
Setup
- Add Google Gemini (PaLM) API credentials for the Gemini chat model used in both cleaning passes.
- Add Google Sheets OAuth2 credentials and select the target spreadsheet for both the clean-record and quarantine writes.
- Create two tabs in the spreadsheet named “Clean Records” and “Quarantine”, and ensure the clean tab has an email column suitable for upserts.
- Update the target schema and rule text to match the fields and validation requirements you want to enforce.
- Activate the workflow, copy the production webhook URL, and configure your source system to POST records to it.