{"product_id":"n8n-webhook-clean-validate-leads-with-gemini-google-sheets","title":"n8n Webhook: Clean \u0026 Validate Leads with Gemini + Google Sheets","description":"\u003ch3\u003eTurn messy inbound leads into clean, validated data—automatically\u003c\/h3\u003e\n\u003cp\u003eThis n8n workflow exposes a \u003cstrong\u003ePOST webhook\u003c\/strong\u003e that cleans and normalizes incoming lead records with \u003cstrong\u003eGoogle Gemini\u003c\/strong\u003e, validates them against strict formatting rules, and then \u003cstrong\u003eupserts valid leads into Google Sheets\u003c\/strong\u003e—or quarantines failures with an \u003cstrong\u003eHTTP 422\u003c\/strong\u003e response.\u003c\/p\u003e\n\n\u003ch3\u003eWhat this workflow does\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eReceives\u003c\/strong\u003e a JSON record via a webhook endpoint.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eDefines a target field schema\u003c\/strong\u003e and cleaning rules for the incoming data.\u003c\/li\u003e\n  \u003cli\u003eUses \u003cstrong\u003eGoogle Gemini (PaLM) chat model\u003c\/strong\u003e to transform the raw record into \u003cstrong\u003eminified JSON\u003c\/strong\u003e that matches the target schema.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eValidates\u003c\/strong\u003e the Gemini output by parsing JSON and checking required fields plus:\n    \u003cul\u003e\n      \u003cli\u003e\n\u003cstrong\u003eEmail\u003c\/strong\u003e format\u003c\/li\u003e\n      \u003cli\u003e\n\u003cstrong\u003ePhone\u003c\/strong\u003e in \u003cstrong\u003eE.164\u003c\/strong\u003e format\u003c\/li\u003e\n      \u003cli\u003e\n\u003cstrong\u003eDate\u003c\/strong\u003e in \u003cstrong\u003eYYYY-MM-DD\u003c\/strong\u003e format\u003c\/li\u003e\n    \u003c\/ul\u003e\n  \u003c\/li\u003e\n  \u003cli\u003eIf validation fails, it sends the previous output and \u003cstrong\u003especific validation errors\u003c\/strong\u003e back to Gemini for a \u003cstrong\u003esecond repair pass\u003c\/strong\u003e, then validates again.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eUpserts\u003c\/strong\u003e valid records into a Google Sheets tab using \u003cstrong\u003eemail as the key\u003c\/strong\u003e and returns the cleaned JSON to the caller.\u003c\/li\u003e\n  \u003cli\u003eIf records still fail after two attempts, it \u003cstrong\u003eappends\u003c\/strong\u003e them to a \u003cstrong\u003eGoogle Sheets “Quarantine”\u003c\/strong\u003e tab and returns \u003cstrong\u003eHTTP 422\u003c\/strong\u003e.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eUse cases\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003eSaaS lead capture where form submissions arrive inconsistent or poorly formatted\u003c\/li\u003e\n  \u003cli\u003eNormalizing leads from multiple sources (web forms, landing pages, partner referrals) into one Google Sheets CRM\u003c\/li\u003e\n  \u003cli\u003eAutomations that must reject invalid lead payloads quickly (with 422) while logging bad data for review\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eTechnical details\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eWebhook\u003c\/strong\u003e (POST endpoint)\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eGoogle Gemini (PaLM)\u003c\/strong\u003e credentials used for both cleaning passes\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eGoogle Sheets\u003c\/strong\u003e OAuth2 for writing to “Clean Records” and “Quarantine” tabs\u003c\/li\u003e\n  \u003cli\u003eNodes used include: \u003cstrong\u003eif\u003c\/strong\u003e, \u003cstrong\u003eset\u003c\/strong\u003e, \u003cstrong\u003ecode\u003c\/strong\u003e, \u003cstrong\u003ewebhook\u003c\/strong\u003e, and \u003cstrong\u003esticky note\u003c\/strong\u003e\n\u003c\/li\u003e\n\u003c\/ul\u003e\n\u003cp\u003e\u003cstrong\u003eSetup:\u003c\/strong\u003e configure Gemini API credentials, set Google Sheets OAuth2, ensure the spreadsheet has “Clean Records” and “Quarantine” tabs, and update the \u003cstrong\u003etarget schema and rule text\u003c\/strong\u003e used by the workflow.\u003c\/p\u003e","brand":"N8N Commerce","offers":[{"title":"Default Title","offer_id":45850707329203,"sku":"N8N-18119","price":47.99,"currency_code":"GBP","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0749\/6279\/6723\/files\/E6ZtDwqRbgvv8IkLIZwRy_alPIdnvi.png?v=1786871520","url":"https:\/\/buyflowscripts.com\/products\/n8n-webhook-clean-validate-leads-with-gemini-google-sheets","provider":"N8N Commerce","version":"1.0","type":"link"}