Build an LLM-powered triage system using n8n, Google Sheets and Gemini

Architect and implement a reliable LLM loop: data normalization, prompt design, structured output parsing, and failover patterns for production triage.

6 min read
LLM triage automation diagram: n8n, Sheet, Gemini, orchestration in blue and black theme

Opening

Triage workflows are supposed to make incident response predictable: a report arrives, the system assigns priority, a technician is dispatched, and the record closes. Reality is messier — freeform intake, missing identifiers, and inconsistent technician statuses turn triage into manual triage queues. Adding an LLM helps by normalising language, extracting structured fields and suggesting priorities, but it also introduces new failure modes: hallucinated SKUs, malformed JSON, and brittle parsers. This guide gives an operator-focused, production-ready pattern using n8n for orchestration, Google Sheets as the canonical ledger, and Gemini as the extraction and classification engine.

*See a practical use-case: automating visual workflow previews*

Understanding LLM-powered triage

An LLM-powered triage loop separates three responsibilities: intake, intelligent triage, and stateful recording. Each has clear inputs, outputs, and failure modes that must be guarded.

  1. Webhook intake — raw payloads from forms, APIs or IoT devices.

  2. Context enrichment — look up machine metadata, recent logs and on-hand parts in Sheets.

  3. AI triage & extraction — Gemini returns a validated JSON with `severity`, `requiredskill`, `summary`, `partsused`, and `safety_concern`.

LLM triage automation diagram: n8n, Sheet, Gemini, orchestration in blue and black theme

Prepare your environment and prerequisites

Before you build:

  • Create a Google service account and share the target spreadsheet with its email.

  • Prepare one spreadsheet with these tabs: `Elevators`, `Technicians`, `Tickets`, `Service Logs`, `Inventory Parts`.

  • Choose n8n hosting: cloud (simpler webhooks) or self-hosted (reverse proxy required).

  • Get a Gemini API key and plan to use `gemini-3.1-flash-lite` for trim latency and cost.

Common pitfall: missing or mistyped identifier fields. If intake lacks `elevator_id` you will see `Unknown elevator id` failures in the code step. Validate incoming JSON schema as the first step.

Configure n8n and Google Sheets

  1. Create the Google Service Account and add the JSON key to n8n credentials.

  2. Share the spreadsheet with the service account address.

  3. Import the workflow into n8n and map node credentials.

  4. Confirm column names: `elevatorid`, `technicianid`, `ticketid`, `partsku` must match exactly.

Flow diagram from Webhook → n8n → Gemini → Google Sheets in blue/black theme

Set up Gemini and dispatch channels

  1. Add the Gemini API key as the PaLM/Gemini credential in n8n.

  2. Create a triage prompt that requests structured output (JSON) and include a strict schema example.

  3. Route dispatches to WhatsApp Business Cloud or an SMS gateway for technicians. Keep a human fallback for `P1` and `safety_concern` events.

If Gemini outputs are malformed, reduce `temperature` to `0.1`, enforce a strict response wrapper (e.g. a fenced JSON block) and run a lightweight JSON schema validation node before acting.

Sheet view: tickets and parsed LLM outputs

Test the setup by running a smoke test

  1. POST a minimal complaint: `{ "elevatorid": "E-100", "complainttext": "noisy motor and doors sticking" }` to the webhook.

  2. Confirm Gemini returns `severity` and `required_skill` and that n8n writes a new Tickets row.

  3. Verify the dispatch node sends a message or the unassigned alert branch triggers when no tech is available.

If the triage agent returns an unexpected field, log the entire prompt and response to an audit sheet for quick rollback.

Advanced: inventory sync and safety flags

  • Parse `partsused` to exact `partsku` values and decrement `Inventory Parts` with idempotent updates.

  • Use `safety_concern` boolean to trigger supervisor escalation and set the next maintenance interval shorter (e.g. 14 days).

  • If a part has no matching SKU, mark the ticket for manual review rather than failing the inventory job.

Understanding limits and constraints

Treat the LLM as a best-effort extractor: rate-limit calls, cache repeated lookups (elevator metadata), and design prompts that limit token usage. Approximate limits should be checked in Gemini docs; implement exponential backoff and request queuing for spikes.

Practical tips:

  • Keep prompts small and include only essential context.

  • Batch non-urgent enrichment (logs, service history) outside the immediate triage path.

  • Log prompt/response hashes for reproducibility and auditing.

Common Errors and Real-World Fixes

  1. Unknown elevator_id Cause: intake payload lacks exact field `elevator_id`. Fix: validate incoming JSON and normalise field names before enrichment.

  1. Malformed AI output Cause: model temperature too high or prompt mismatch. Fix: set Gemini `temperature` to `0.1`, use a strict JSON schema in the prompt, and validate the response with a schema node.

  1. No technician available Cause: roster or status values are incorrect. Fix: add a `status` field to `Technicians` and test the selection logic; provide an `unassigned` alert branch.

  1. Inventory not updated Cause: `partsused` lacks matched `partsku`. Fix: add SKUs to `Inventory Parts` and make the parts mapping tolerant (fuzzy match with threshold).

  1. Webhook 404/403 Cause: workflow inactive or endpoint not exposed. Fix: ensure the workflow is active, the webhook path matches, and credentials (if any) are up to date.

Building reliable workflows around triage

Operational patterns to adopt:

  1. Standardise prompts — keep them in version control and treat changes as releases.

  2. Human review gate — require sign-off for `safety_concern` tickets.

  3. Audit logs — store prompt/response pairs and key metadata in a secure Sheets audit tab.

Safety recommendations:

  • Maintain a single source of truth for inventory and technician availability.

  • Monitor model health (malformed outputs) and roll back prompt changes quickly.

  • Rate-limit and queue LLM calls so downstream systems do not see burst failures.

Production checklist

  • Spreadsheet tabs and column names validated against node mappings.

  • Google service account shared with the spreadsheet and credential added to n8n.

  • Webhook smoke tests passed and dispatch channel verified.

  • Gemini prompt schema validated with edge-case examples.

  • Inventory and reorder flows tested with low-stock simulation.

Conclusion

An LLM-enhanced triage system cuts time-to-assign and improves diagnostics when built with clear boundaries: LLMs extract and suggest, n8n orchestrates workflow logic and retries, and Google Sheets acts as an auditable ledger. Expect to iterate on prompts and parsers; keep humans in the loop for safety-critical decisions and maintain tight monitoring during the first weeks of production. Updated for 2026.

Frequently Asked Questions

Yes — use a public webhook endpoint (or a reverse proxy) and ensure the Google service account JSON is available to the instance; share the spreadsheet with the service account email.