AI Compliance Agent: RAG Design for Hospital Accreditation
AI Engineering

AI Compliance Agent: RAG Design for Hospital Accreditation

AI Summary

In October 2026 Paulo H. Alkmin designed, in a two-day architecture engagement for a large Brazilian hospital network, an AI agent that finds gaps between internal policies, documented processes and the Joint Commission International (JCI) accreditation standards plus current Brazilian law. The deliverable was the architecture: solution diagram, API contract, three architecture decisions with trade-offs and the MVP scope. The design reuses the hospital's existing AI platform (vector database with RAG, LLM gateway, guardrails, MCP gateway to internal systems, short-term memory) and adds an agent API, a job queue, an orchestrator with four steps (process mapping, policy retrieval, completeness check, guardrail) and a versioned requirements catalog. Three architecture decisions: a requirements catalog with IDs, sources, validity dates and verifiable criteria, approved by Compliance, instead of open-ended RAG on every run, so results are repeatable and coverage is measured as X of N requirements; asynchronous analysis (202 Accepted plus job ID, idempotency key, per-requirement checkpoints, bounded retries, dead-letter queue, pinned versions of catalog, policies, model, prompt and rules); and market benchmarks kept outside the official base, marked as non-regulatory, fetched only from an allowlist of public sources with no internal data leaving, and promoted to the catalog only by Compliance. Each requirement ends as covered, partial, not found or inconclusive; not found never counts as proof of absence, every finding cites policy, version and section, and a person makes every change. The MVP covered one pilot area, JCI only, the deterministic layer only, with success measured by 100% of applicable requirements receiving a state, 90% agreement with Compliance as the initial target, false negatives measured separately and time compared with the manual review.

Architecture for an AI agent that checks a hospital network's internal policies against JCI accreditation standards, built on a versioned requirements catalog and human review.

October 20, 2026
AI Engineering
Technologies
RAGAI AgentsMCPAsync APIsHuman-in-the-loopHealthcare ComplianceJCI AccreditationLGPD

In October 2026 one of Brazil's largest hospital networks, through an IT consultancy, needed the architecture for an AI compliance agent that would find what its policies were missing against accreditation standards. The brief: two business days, then 30 minutes to present and defend the choices in front of the team. The deliverable was the architecture itself, with the solution diagram, the API contract, three decisions with their trade-offs and the MVP scope. Below is that design, without the client's name or the details of its internal platform.

The problem

The hospital's Compliance team needed to know, area by area, what was missing from internal policies and documented processes compared with what the reference frameworks require. In practice that meant the Joint Commission International (JCI) accreditation standards and current Brazilian law, both already stored in the hospital's knowledge base, plus market benchmarks that weren't there yet. Hundreds of people own policies across the organization. The output was easy to state: for each area, recommend which policies to review, add or update.

The brief also said to reuse the AI platform the hospital was already building: a vector database with RAG, an LLM gateway, an MCP gateway into internal systems, short-term memory, a batch workflow engine. Two of those pieces, the guardrail layer and the MCP gateway, weren't due until December.

The deck opened with my assumptions, each one paired with what would change if it were wrong. If the standards were already stored requirement by requirement, the catalog below becomes an import instead of an extraction and the MVP gets shorter. If the policies were loose files instead of a system, an ingestion and versioning pipeline has to come first.

The rule the design hangs on

Whatever is regulatory has to be auditable and repeatable. The rest can be flexible.

That sentence settled almost every trade-off. If Compliance runs the analysis on infection control twice, with the same policies and the same standards, it has to get the same answer, and an auditor has to be able to see why.

Decision 1: why not just run RAG on every analysis?

The fast option was right there. The RAG pipeline already existed, so the agent could ask the model "what does JCI require for this area, and do our policies cover it?" on every run.

I turned it down. That result shifts with retrieval, chunking and the prompt. Worse, a requirement that retrieval never surfaces doesn't appear as a gap. It just isn't in the report, and nobody notices it's missing.

So the design adds a requirements catalog: every requirement from the standards and the law as a row with an ID, a source, validity dates and verifiable criteria. The agent pre-extracts it from the documents, a person in Compliance approves each version, and RAG does what it's good at, which is finding evidence in the policies for one specific criterion at a time. Coverage turns into a number: X of N requirements, per area.

The cost is curation up front, and Compliance owns the catalog from then on, updating it whenever a standard changes. I said that plainly in the presentation.

It's the price of being able to defend the result.

Decision 2: asynchronous analysis with checkpoints

An area has dozens of requirements, and each one means a search plus an LLM call (what that costs at scale is in What a RAG System Actually Costs). That takes minutes. A synchronous API would hit timeouts, and a failure halfway through would throw away everything already evaluated.

Starting an analysis returns 202 Accepted with a job ID and puts the job on a queue. Workers are idempotent, concurrency against the LLM gateway is capped, every evaluated requirement is saved as a checkpoint, and a failure resumes where it stopped, with bounded retries and a dead-letter queue. The same Idempotency-Key with the same payload returns the same job. Each job also pins the version of everything it used: catalog, policies, model, prompt and rules. Six months later you can still reconstruct why a gap was flagged.

Five endpoints cover the MVP:

EndpointPurpose
POST /areas/{id}/processesRecord the process mapping done with area managers
POST /analysesStart an area analysis (async, 202 + job ID)
GET /analyses/{id}Status, current step and progress
GET /analyses/{id}/gapsGaps and recommendations, with source and layer, paginated
PATCH /gaps/{id}Compliance accepts, rejects or comments

Only the trigger is asynchronous. Reads are synchronous, and a callback URL is optional.

Decision 3: benchmarks stay out of the official base

The second layer brings in market practice the hospital doesn't have yet. Useful, and exactly the kind of thing that must never quietly turn into an obligation.

Benchmark findings come out marked as non-regulatory, always with their source, and only from an allowlist of public sites. No internal data goes out with the web search, which in a hospital under LGPD isn't up for discussion. A benchmark never enters the official base by itself. If Compliance approves it, it becomes an internal requirement in the catalog, with its own ID.

The trade-off is that the same external searches repeat across analyses and their results drift with the web. For a layer that only suggests, I can live with that.

Can an AI agent prove a policy is missing?

No, and the design makes sure it never tries.

Every requirement ends in one of four states: covered, partial, not found or inconclusive. "Not found" means the search found no evidence. It doesn't prove the policy is missing. Inconclusive goes straight to human review. Every finding cites the policy, its version and the section.

The agent only recommends, and a person changes the policy. Compliance answers for the accreditation, so the model doesn't get the last word.

MVP scope

The first delivery was small on purpose: one pilot area with many JCI requirements, the deterministic layer only, JCI only, that area's catalog reviewed by Compliance, the analysis, gap and review APIs, and the internal web front end the platform already planned. The only users would be the Compliance team.

Left for later: the benchmark layer, legislation in the catalog, the remaining areas and their policy owners, automatic re-analysis when a standard changes, promoting benchmarks into the catalog, and Teams notifications.

Success was defined before any build. Every applicable requirement ends with a state. Agreement with Compliance starts with a 90% target. False negatives are measured separately, on a sample. Time is compared against the manual review.

The risks were named too. Guardrails and the MCP gateway arriving only in December meant output rules in the orchestrator and direct API calls until then, a temporary path that wouldn't be built at all if they arrived earlier. Catalog extraction errors are caught by human approval before each version is published. Sensitive data in logs and prompts gets an audit trail with defined access and retention.

What the design changes for the hospital

Today, finding the gaps between hundreds of policies and the JCI standards is reading work: someone in Compliance opens the standard, opens the policies and compares them line by line. With the catalog in place, that comparison runs per area in minutes, and the team's time goes to what only they can do, deciding whether "partial" is acceptable and what to rewrite.

Coverage becomes something tracked over time instead of something discovered in a mock survey. "X of N requirements covered" for each area is a figure a director can follow month to month, and when it drops, it drops before the surveyors arrive.

When JCI publishes a new edition of its standards, or a law changes, the work becomes a catalog update and a re-run, instead of a manual re-read of every policy that might be affected.

And because each job pins its versions and every finding points to a section of a specific policy version, the hospital can show an auditor how a gap was found, not only that it was closed.

Proposed components

  • New: agent API with five endpoints, a job queue with redelivery and a dead-letter queue, an orchestrator running four steps (process mapping, policy retrieval over MCP, completeness check, guardrail), the requirements catalog, and a store for jobs, gaps and reviews
  • Reused from the hospital's platform: vector database and RAG, LLM gateway, guardrails, MCP gateway to internal systems, short-term memory, observability, audit and FinOps
  • Phase 2: allowlisted web search for the benchmark layer

Building this kind of thing means deciding what has to be repeatable before picking a model, and designing the "I don't know" answers before the happy path. Most RAG projects in regulated sectors skip both, and that's where every AI architecture consulting engagement I take on starts. Do you know which of your agent's answers you could defend in an audit?