Inspiration

Every year, pharmaceutical manufacturers are hit with severe product contamination crises, leading to catastrophic Class-I drug recalls. While modern manufacturing facilities log extensive data, the post-market feedback loop remains dangerously manual.

When a contaminated batch enters the global supply chain, the warnings don't arrive in clean Excel sheets. They arrive as chaotic, unstructured text: a patient emailing about extreme burning sensations, an online portal form logging a sudden vision drop, or an unformatted doctor's note tracking corneal inflammation. Because traditional automation relies on strict, rules-based programming, it is completely blind to this unstructured mess. Human safety officers are forced to manually read, sort, and cross-reference thousands of isolated complaints against massive supply chain ERP databases.

By the time a human team recognizes a statistical pattern, traces the root cause back to a specific manufacturing facility, and alerts regional distributors, weeks or months pass. This delay costs human lives, results in permanent patient harm, and inflicts billions of dollars in legal liabilities on enterprises. We built PharmaTrac AI to eliminate this human translation bottleneck entirely—replacing slow, reactive workflows with an autonomous, event-driven, real-time safety control plane.

What it does

PharmaTrac AI is an autonomous, multi-agent pharmacovigilance and global recall orchestration platform. It continuously monitors incoming post-market data channels, automatically synthesizes complex cross-document insights, and coordinates enterprise-wide containment actions.

When an unstructured patient complaint hits an enterprise inbox, PharmaTrac AI instantly initializes a UiPath Maestro Case. It coordinates a highly specialized network of Gemini 1.5 Flash agents:

The Clinical Severity Parser: Interrogates the messy patient text log using advanced NLP to score symptom severity.

The Supply Chain Cross-Auditor: Pulls the referenced batch code and queries structured logistics records inside the UiPath Data Service to track the exact manufacturing facility, material suppliers, and active distribution nodes.

Instead of evaluating data in silos, the agents execute cross-document reasoning. If multiple independent complaints across different regions trace back to the same manufacturing plant, the system flags a systemic contaminant risk.

For strict compliance and safety, the automation utilizes a Human-in-the-Loop (HITL) architecture. It freezes background operations and pushes a high-priority, red-alert diagnostic dashboard to UiPath Action Center. Once a safety executive clicks a single button to validate the threat, a background UiPath RPA robot instantly updates the core ERP system to lock down the toxic batch, alerts regional warehouses, and stops further distribution in seconds instead of weeks.

How I built it

PharmaTrac AI is built entirely on the UiPath Automation Cloud using Maestro Case Management as the central orchestration engine. The entire system is modeled as a BPMN 2.0 state-driven case plan with six distinct stages: Received, Enriching, Cluster Analysis, Human Action, Recall Decision, and Closed.

Case Architecture: I designed a structured caseplan.json that defines the full lifecycle of a pharmacovigilance complaint. Each stage has strict entry conditions, exit rules, and required tasks — ensuring no case can skip a critical safety checkpoint. The case schema tracks 26 custom variables covering everything from complaint_id and batch_id to cluster_detected, signal_strength, and review_decision.

Agentic Pipeline: I built eight specialized agents using UiPath Agent Builder powered by Gemini 2.5 Flash:

PharmaSignal_CaseTrigger — an RPA process that validates incoming JSON payloads, checks for duplicates, and initializes the Maestro Case. ComplaintIntelligenceAgent — an LLM cognitive agent that parses unstructured patient narratives to extract product names, batch IDs, symptom categories, severity scores, and extraction confidence. BatchLookupAgent — queries internal manufacturing databases to identify the production facility, distribution geography, and historical complaint records for the flagged batch. ClusterDetectionAgent — performs cross-document statistical reasoning. If multiple independent complaints trace back to the same batch or factory exceeding a safety coefficient (>3 identical symptom events), it flags a cluster warning and generates a diagnostic safety report. EscalationApp_Final — a custom UiPath App deployed in Action Center that renders a dark-themed, glassmorphic executive dashboard for Human-in-the-Loop review. RecallDecisionAgent — synthesizes the safety officer's sign-off into a structured recall recommendation report. CaseClosureAgent — compiles the full case history into an auditable closure report and updates safety records. Gmail Integration — uses the UiPath Google Gmail Connector to fire urgent distributor alerts on approved recalls. Human-in-the-Loop: The critical innovation is the dedicated Human Action stage (Stage 4). When the cluster analysis detects a potential safety signal, Maestro Case pauses all background automation and pushes a high-priority task to a Safety Officer. The EscalationApp presents extraction data side-by-side with raw complaints, cluster reasoning, and signal strength — giving the officer full context to Initiate a Recall, Escalate to Lab, or Dismiss

Challenges we ran into

Unstructured text is genuinely chaotic. Real pharmaceutical complaints don't follow any template. A single email might contain medical jargon, colloquial descriptions ("my eyes feel like they're on fire"), and irrelevant context mixed together. Getting the ComplaintIntelligenceAgent to reliably extract structured fields like batch IDs and symptom categories from this noise required extensive prompt engineering and confidence thresholds. We implemented a failsafe gate: if extraction confidence falls below 80%, the case bypasses normal processing and fast-tracks directly to human review.

Cross-document reasoning at scale. The ClusterDetectionAgent doesn't just analyze one complaint — it needs to reason across the entire history of complaints for a given batch. Designing prompts that could synthesize patterns across multiple independent reports while maintaining factual accuracy was one of our hardest engineering challenges. We solved this by feeding structured JSON summaries of historical complaints as context, rather than raw text.

Case plan state management. UiPath Maestro Case enforces strict entry/exit conditions between stages. Debugging cases that got stuck between stages due to missing variable mappings or incorrect binding references was time-consuming. We learned to treat the caseplan.json as critical infrastructure code — versioning it carefully and validating every variable reference against the schema.

ERP fallback handling. In production environments, the BatchLookup database isn't always available. We had to implement a cached fallback schema so that cases could proceed through the pipeline even during ERP outages, with a warning task logged for later reconciliation.

Binding complexity. The UiPath bindings system for connecting agents, apps, and connectors across different orchestrator folders required careful management. With eight agents, multiple app versions, and a Gmail connector, the bindings_v2.json grew to over 70 binding entries. Keeping these synchronized across development and deployment was a constant challenge.

Accomplishments that we're proud of

A complete, end-to-end agentic safety pipeline. PharmaTrac AI isn't a prototype or a single-agent demo — it's a fully orchestrated, six-stage case management system where every stage has real automation running behind it. From the moment a complaint arrives to the moment a recall alert hits a distributor's inbox, the entire workflow is automated with human governance built in.

Cross-document cluster detection. Most AI demos analyze documents in isolation. Our ClusterDetectionAgent performs genuine multi-document statistical reasoning — comparing the current complaint against the full history of a batch to detect systemic contamination patterns. This is the kind of reasoning that takes human teams weeks to perform manually.

Production-grade resiliency. We didn't just build the happy path. We built failsafe routing for low-confidence extractions, cached fallbacks for ERP outages, exponential backoff retries for LLM API calls, and full audit trails. This is enterprise-ready architecture, not a hackathon demo.

A beautiful, functional HITL dashboard. The EscalationApp_Final isn't a placeholder form — it's a dark-themed, glassmorphic executive interface that presents extraction data, cluster reasoning, signal strength, and decision buttons in a layout designed for high-stakes, time-critical decision-making.

The entire pipeline runs on UiPath's native platform. We didn't bolt together five different SaaS tools. Every component — case management, agent orchestration, human tasks, app dashboards, email notifications — runs natively within UiPath Automation Cloud. This proves that Maestro Case can serve as a true enterprise control plane for agentic AI.

What we learned

Agentic orchestration is fundamentally different from traditional RPA. In classic RPA, you script deterministic steps. With agentic systems, each agent produces probabilistic outputs that feed into the next agent's context. Designing for this uncertainty — confidence thresholds, fallback routing, human escalation gates — is a completely different engineering discipline.

Human-in-the-Loop isn't optional for high-stakes domains. Early in development, we experimented with fully autonomous recall decisions. The results were technically impressive but ethically unacceptable. A single false positive could trigger a recall costing millions; a false negative could cost lives. We learned that the most valuable role for AI in pharmacovigilance isn't replacing humans — it's compressing weeks of manual analysis into seconds and presenting a clear, synthesized recommendation for a human expert to validate.

Case management is the missing governance layer for AI agents. Without Maestro Case, our agents would be powerful but ungoverned. The case plan gives us transaction boundaries, audit trails, SLA enforcement, and state-driven routing. We learned that the future of enterprise AI isn't just better models — it's better orchestration and governance around those models.

AI coding agents accelerate enterprise development. Using Gemini CLI and Claude Code to co-develop our schemas, bindings, and validation suites saved us significant development time. The agents were particularly effective at generating the repetitive but critical JSON configuration files that power UiPath's case plan infrastructure.

What's next for PharmaTrac AI

Multi-channel ingestion. Currently, complaints enter via API. We plan to integrate direct monitoring of email inboxes, regulatory portal feeds (FDA MedWatch, EMA EudraVigilance), and even social media channels using UiPath Document Understanding for handwritten notes and scanned reports.

Predictive signal detection. Today, the ClusterDetectionAgent flags patterns after they emerge. We're developing a predictive module that uses time-series analysis on complaint velocity — detecting early-stage signals before the cluster threshold is breached, giving enterprises even earlier warning.

Global regulatory auto-filing. After a recall decision, the system could auto-generate and submit regulatory filings in the correct format for each jurisdiction (FDA MedWatch in the US, EMA ICSR in Europe, PMDA in Japan), reducing the compliance burden from days to minutes.

Digital twin integration. Connecting PharmaTrac AI to manufacturing digital twins would allow the system to correlate complaint clusters with specific production line anomalies — such as temperature excursions or raw material batch changes — enabling true root-cause automation.

Multi-tenant enterprise deployment. We're designing a scalable architecture where multiple pharmaceutical companies can run independent PharmaTrac AI instances on shared UiPath infrastructure, with strict data isolation and tenant-specific agent configurations.

Built With

  • agentbuilder
  • mastrocase
  • uipath
  • uipathstudio
Share this project:

Updates

Submission history