Capture Event -> Draft Description -> Suggest Severity -> Find Similar -> Hand to QA

Deviation Triage and Similar-Event Finder

This agent takes a new event and drafts an initial deviation description, suggests a classification with the rule behind it, and pulls the most similar past deviations along with how they were closed. QA reads the draft and the precedents and decides the classification and the path forward.

The Problem

Same deviation as last spring. Nobody remembered the fix.

A batch record shows a mixing step held ten minutes too long. The analyst writes a rough note, and it sits for two days before anyone classifies it. Six months ago the same line had nearly the same event with a clean resolution, but that history lives in a closed record nobody thinks to search. The team re-investigates from scratch and lands somewhere different than last time.

What Changes

A first draft with the precedents attached

The agent turns the raw event notes into a structured deviation description, suggests a severity and names the rule that pointed to it, and searches the deviation library for the closest past events. It returns the top matches with their classifications and how they were resolved. QA decides the actual classification and whether the precedent applies.

Humans stay in control: the agent drafts and suggests, but QA sets the classification and signs the deviation record.

HOW THE AGENT WORKS

TRIGGERLLMAPIDECISIONACTIONWAIT
TRIGGERNew event loggedFires when an event is logged in the QMS or a deviations inbox.
APIPull event detailsReads the event notes plus batch and step context.
APISearch similar deviationsFinds the closest past deviations by text similarity.
LLMDraft and suggest severityDrafts the description and suggests a severity with the rule that fired.
DECISIONClose match found
LLMAssemble the packageCombines the draft with the top precedents and their outcomes.
ACTIONSend draft to QADelivers the draft, suggested severity, and precedents to QA.
The agent does not classify the deviation or close it. Your QA reviewer does. The agent removes the blank-page draft and the manual hunt through closed records for similar events.

HOW TO BUILD IT

Three levels of depth. Pick the one that matches where you are.

For the ops person who needs to understand what's involved and brief their team.

New Event and HistoryRaw event notes and the deviation library
The AgentWorkflow engine + LLM
QA ReviewerDraft, suggested severity, similar events

WHAT YOUR TEAM PROVIDES ONCE

  • Event intake - the raw notes, batch, and step where the event happened
  • Deviation history - the library of past deviations and their descriptions
  • Resolution records - how each past deviation was classified and closed
  • Classification rules - the severity criteria your site uses
  • Deviation template - the format your QMS expects for a new record
What happens day-to-day: someone logs a rough event note. Within minutes QA has a structured draft description, a suggested severity with the rule that fired, and a short list of similar past deviations with their outcomes. QA edits the draft, sets the real classification, and files the record.

For the IT person or technical lead who needs to scope the integration.

INQUIRY SOURCES

New event details from the QMS intake form or an email inbox.
Historical deviation text and outcomes exported from the QMS.
Site classification rules held as a rules table or SOP.

WORKFLOW ENGINE (N8N)

New event logged
Fetch event details
Search similar past deviations
Draft description and severity
Is a close match found
Assemble draft and precedents
Send draft package to QA

CONNECTS TO

QMS (Veeva Vault QMS / MasterControl / TrackWise)Read: new event, historical deviations, resolutions. Write: draft deviation as a draft record.
Similarity search (Pinecone / pgvector / Elasticsearch)Read: embeddings of past deviation text. Write: nothing.
Rules table (SharePoint / Confluence / spreadsheet)Read: severity classification criteria. Write: nothing.
Notification (Slack / Teams / Email)Read: nothing. Write: draft package and link to QA.
WITHOUT PMS API

Without API access, QA pastes the event note into the agent and provides a periodic export of closed deviations for the search index. Drafts still generate, but precedents reflect the last export rather than live records.

WITH PMS API

With API access to the QMS and a vector index over past deviations, the agent drafts and finds precedents within minutes of an event being logged. Best experience.

For the person who wants to build this agent step by step. Each node below maps to an n8n workflow node.

TRIGGERNode 1
Trigger - fires on a new event
Webhook from the QMS intake form, or an IMAP Email Trigger watching a deviations inbox.
Output: The raw event text and metadata.
APINode 2
API - pull event details
HTTP Request to the QMS for the full event record and the batch and step context.
Output: Structured event fields plus free-text notes.
APINode 3
API - search similar deviations
Embed the event text and query the vector store for nearest past deviations. Return top five with scores.
Output: Top matches with IDs, similarity scores, and outcomes.
LLMNode 4
LLM - draft description and severity
LLM node that writes the description and suggests a severity from the rules. Set temperature to 0.
Output: { description, suggested_severity, rule_fired }
You draft pharmaceutical deviation records for QA review. Given the raw event notes {event_notes}, the batch and step context {context}, and the site severity rules {rules}, write a clear factual deviation description and suggest a severity. Name the specific rule that led to the severity. Do not decide the final classification. Return JSON with description, suggested_severity, and rule_fired. Respond ONLY with valid JSON. No explanation.
INPUT
event_notes='Mixing step held 10 min beyond the 30 min max for batch B-5521'; context={batch:B-5521, step:mixing, unit:V-2}; rules=[{id:SEV-2, text:'process parameter exceeded without immediate product impact'}]
OUTPUT
{"description":"During manufacture of batch B-5521, the mixing step at unit V-2 was held for 40 minutes against a maximum of 30 minutes. The excursion was noted at the step and no immediate product impact was observed.","suggested_severity":"Major","rule_fired":"SEV-2: process parameter exceeded without immediate product impact"}
DECISIONNode 5
Decision - route on match strength
IF node: if the top similarity score is above the set threshold, include precedents in the package.
Output: Events with strong precedents on one branch.
LLMNode 6
LLM - assemble the package
LLM node that summarizes the draft with the matched precedents for QA.
Output: { summary, precedents[] }
You assemble a deviation triage package for QA. Given the draft {draft} and the similar past deviations {matches}, produce a short summary QA can act on. For each match include its id, how it was resolved, and one line on why it is similar. Return JSON with summary and precedents (array of id, resolution, why_similar). Respond ONLY with valid JSON. No explanation.
INPUT
draft={suggested_severity:'Major'}; matches=[{id:DEV-1188, resolution:'closed, no CAPA, extended-hold shown acceptable', score:0.91}]
OUTPUT
{"summary":"One close precedent for an over-hold on the same unit, resolved without CAPA.","precedents":[{"id":"DEV-1188","resolution":"Closed with no CAPA after extended hold shown acceptable","why_similar":"Same mixing over-hold on a comparable unit"}]}
ACTIONNode 7
Action - send draft to QA
Slack node posts the draft, suggested severity, and precedents to the QA reviewer with a link to accept or edit.
Output: A draft package delivered to QA.
MVP vs Advanced — Where To Start
MVP — START HERE
  • Start with one deviation type such as parameter excursions
  • Index one or two years of closed deviations
  • Let the agent draft the description only
  • Show the top three precedents, not a long list
  • Keep every draft as a draft record
  • Tune severity rules and match threshold with QA
ADVANCED — ADD LATER
  • =+ Cover more deviation types with rule text
  • =+ Pull events and history live from the QMS
  • =+ Re-embed the deviation library on a schedule
  • =+ Add CAPA outcomes to each precedent
  • =+ Route the draft to the right QA reviewer
  • =+ Surface a recurring-event signal on repeats

Full Video Walkthrough Coming Soon

Watch the agent turn a raw event note into a draft with precedents.

Register to be notified

Everything on this page is free to learn.

When you're ready to build — do it yourself or bring us in.

OTHER AGENTS IN LEASING & MARKETING

Reads the approved change, finds who needs retraining, drafts the assignments
Ranks held lots by ageing risk and the one blocker to clear.
Maps every procedure, spec, and validation a change touches and drafts the assessment
Clusters complaints and out-of-spec results across batches, flags the signal early

Frequently asked questions

Deviation Triage and Similar-Event Finder is an AI agent that drafts the deviation, suggests a severity, finds how similar events were resolved.
Same deviation as last spring. Nobody remembered the fix. The Deviation Triage and Similar-Event Finder addresses this: drafts the deviation, suggests a severity, finds how similar events were resolved.
No. Your team stays in control. The agent does not classify the deviation or close it. Your QA reviewer does. The agent removes the blank-page draft and the manual hunt through closed records for similar events.