deviation-capa¶
Structure a GMP deviation investigation (timeline, 5 whys, Ishikawa), assess product impact, and draft CAPA with owner, due date and effectiveness check. Use when asked to write up a deviation, root cause analysis or CAPA plan.
| Stage | Quality and compliance |
| Tier | 2 (template and rubric) |
| Standards | ICH Q9(R1), ICH Q10, EU GMP Chapter 8, EU GMP Chapter 1, 21 CFR 211.192 |
Minimum pharmaskills |
0.4.0 |
| Inputs | deviation description, batch context, process records |
| Outputs | investigation docx, investigation md, capa csv, capa check json |
| Verified by | quality check-capa, docs build, docs detect-pii |
Draft for qualified review. Not a validated system. QA owns classification, root cause conclusion, disposition and CAPA approval.
Install only this skill: pharmaskills skills install --agent claude-code --skill deviation-capa (see Install).
Purpose¶
Help a quality or manufacturing professional turn a deviation description into a structured, reviewable investigation record and a CAPA plan: an event timeline, a documented root-cause method (5 whys, Ishikawa), a product impact assessment, and CAPA actions that each carry an owner, a due date and an effectiveness check. Everything is a draft for qualified review. Quality assurance (QA) decides classification, the root cause conclusion, batch disposition and CAPA approval; this skill never does.
When to use / when not to use¶
Use to structure a deviation, out-of-specification follow-up narrative or quality event, to check that an investigation and CAPA list are complete before QA review, or to propose effectiveness checks.
Do not use for: batch release or disposition decisions, medical advice or patient-level
treatment advice (decline and point to a clinician or the responsible qualified person), final
approved investigation records, or real patient or personal data (run
pharmaskills docs detect-pii and recommend de-identification). Out of scope: pharmacovigilance
case handling (use icsr-e2b) and medical device complaint handling.
Inputs¶
Required: a deviation description (what, where, when, who found it, which process step) and batch context (product, batch or lot identifiers, equipment, specification, quantity affected). Optional: process or batch records, equipment logs, earlier similar deviations, the site SOP for deviations.
Ask once for anything missing, then proceed with stated assumptions and [DATA NEEDED: ...]
placeholders. State the region assumed: US FDA with ICH unless told otherwise; for EU sites
the EU GMP chapters apply. If pharmaskills is not installed, say so (uv tool install
pharmaskills, then check pharmaskills --version against min_pharmaskills), produce the
Markdown record from the template and mark it unchecked.
Workflow¶
- Intake. Run
pharmaskills docs detect-piion supplied files and warn on findings. Restate the event in one factual paragraph with no cause or blame. - Timeline. Build a dated, ordered table of events from the sources only. Unknown times
become
[DATA NEEDED: ...]. Usetemplates/investigation.md. - Containment. List immediate actions and quarantined material as reported. Do not add actions that were not taken.
- Root cause. Apply a named method from
references/root-cause-methods.md: 5 whys, an Ishikawa (fishbone) table by category, and where warranted a fault tree or FMEA. Separate facts, hypotheses and the confirmed root cause. If evidence is insufficient, write "root cause not yet established" and list the verification experiments; never state a cause that the evidence does not support. - Product impact assessment. Use
references/product-impact.md: which batches, materials, quality attributes and patients could be affected, link to ICH Q9(R1) risk reasoning, and list data needed. The impact conclusion and disposition are left to QA as placeholders. - CAPA. One row per action in
capa.csvwith columnscapa_id,action,type,owner,due_date, effectiveness_check(seereferences/capa-fields.md). Owner is a role or the placeholder[OWNER: <role>]; never invent a named person. Due date isYYYY-MM-DDor a placeholder. Each effectiveness check states the metric, the sample and the time window. - Build. Write
out/investigation.mdand build the DOCX withpharmaskills docs build out/investigation.md --out out/investigation.docx --skill deviation-capaso the draft banner and the provenance block are inserted. - Check.
pharmaskills quality check-capa out/investigation.md out/capa.csv --out out/capa_check.json. Exit 2 lists what is missing; fix and rerun, at most 3 iterations. - Report using the output contract.
Output contract¶
Under out/:
| File | Content |
|---|---|
investigation.docx (and .md) |
Timeline, containment, root cause method, product impact assessment, CAPA summary; draft banner and provenance block |
capa.csv |
One row per CAPA: id, action, type, owner, due date, effectiveness check |
capa_check.json |
Result of quality check-capa: methods found, missing fields, warnings |
State plainly: which root-cause method was used, whether the root cause is established or open, the count of CAPA rows and placeholders left, and what QA must decide.
Verification¶
Run pharmaskills quality check-capa and report pass or fail: a named root-cause method,
product impact assessment present, timeline present, and every CAPA row with action, owner (or
[OWNER: ...]), due date and effectiveness check. On exit 2 fix and rerun up to three times,
then report what remains. A passing check proves completeness only, not that the root cause is
correct or the impact assessment sound; QA must read them. Replay on the synthetic example
examples/quality/deviation-capa/ passes all eval cases.
Guardrails¶
- Insert the draft banner in every generated document; never call an investigation approved, closed, final or validated.
- Never fabricate batch data, test results, dates, names, deviation numbers or regulatory
precedents. Unknown values become
[DATA NEEDED: ...]. Refuse requests to close a deviation without evidence, backdate entries, or hide an impact. - Never decide batch disposition, release or rejection; present the assessment and the decision as QA's.
- Do not attribute cause to a person ("human error") as a stopping point; ask why the system
allowed the error (see
references/root-cause-methods.md). - Decline medical advice; outside drug development quality work point to a clinician.
- State the region assumed. Product that may reach patients with a suspected quality defect can have reporting duties (for example field alerts or recall decisions) that remain the user's; this output does not replace them.
- Degrade gracefully: no network is needed; without the tools package produce the template record, marked unchecked.
References¶
references/root-cause-methods.md- 5 whys, Ishikawa, fault tree, FMEA and how to record themreferences/product-impact.md- structure of a product impact assessmentreferences/capa-fields.md- CAPA row fields, effectiveness check patterns- Public sources: ICH Q9(R1) Quality Risk Management, ICH Q10 Pharmaceutical Quality System (CAPA system element), EU GMP Chapter 1 (deviations in the quality system) and Chapter 8 (complaints, quality defects and product recalls; root cause analysis and CAPA for quality defects), 21 CFR 211.192 (investigation of discrepancies). Section numbers are given for navigation only; verify against the current text. https://database.ich.org
Templates: templates/investigation.md, templates/capa.csv. Script: scripts/check_capa.sh.
Examples¶
Worked example with outputs and refusal samples: examples/quality/deviation-capa/. Synthetic
inputs: skills/deviation-capa/evals/fixtures/ (deviation report and batch context).
Worked example¶
Committed example with inputs and outputs: examples/quality/deviation-capa/.
Inputs (synthetic): skills/deviation-capa/evals/fixtures/deviation_report.md and
batch_context.md. The product, batch and reference are invented.
pharmaskills docs build out/investigation.md --out out/investigation.docx --skill deviation-capa
pharmaskills quality check-capa out/investigation.md out/capa.csv --out out/capa_check.json
File in out/ |
Origin |
|---|---|
investigation.docx, investigation.md |
drafted by the agent, built with the deterministic DOCX builder (draft banner, provenance) |
capa.csv |
one row per CAPA with owner placeholder, due date and effectiveness check |
capa_check.json |
tool output of quality check-capa |
refusal_*.md |
what a correct agent says for the adversarial cases |
The root cause is deliberately left "not yet established" and the batch disposition is a
[DATA NEEDED: ...] placeholder: QA decides both. Synthetic data only. Not a validated
system; for qualified review (quality assurance).
Skill source: skills/deviation-capa/SKILL.md