Guide Architectural governance 8 min read

Governing FHIR Integrations in AI-Assisted Development

A FHIR integration depends on versions your team chose: the FHIR release, the US Core guide, the SMART scopes. An AI coding agent knows every version and none of your choices. Write those choices down as decisions, then match each one to the check that can catch it.

The contract lives outside your repository

A healthcare integration that reads patient records over Fast Healthcare Interoperability Resources (FHIR) depends on several specifications your team does not write. Health Level Seven (HL7), the standards body behind FHIR, publishes the base specification. Implementation guides narrow it for a country or a use case. Authorization follows the SMART App Launch guide, whose scopes are the permission strings an app requests, such as read access to one patient's lab results. Large exports follow the Bulk Data Access guide.

In the United States, the Office of the National Coordinator for Health Information Technology (ONC) names exact versions of these for certified products. The certification companion guide for the standardized API criterion, section 170.315(g)(10) of Title 45 of the Code of Federal Regulations (CFR), lists the standards adopted in regulation:

Newer versions exist. HL7 has published FHIR R5. The US Core home page lists 9.0.0 as its current version, and it is still based on R4. A team that ships a FHIR integration has therefore picked a FHIR version, a US Core version, a SMART version and a set of scopes. Those picks are architecture decisions. They bind the team's code to servers it does not control.

An AI coding agent writing that code does not know which choices your team made. It knows FHIR in general, across every version it has seen.

This guide covers which of those choices to write down and which check can catch each one. Mneme, the open-source tool we build, checks code changes against a team's recorded architecture decisions; the later sections say which of these checks it can run and which it cannot.

Where an AI coding agent gets FHIR wrong

The four cases below are hypothetical. We have not measured how often agents produce them. Each one compiles, can pass ordinary unit tests, and still breaks a decision.

It mixes versions

An agent asked to add a medication feature to a Java service pulls in hapi-fhir-structures-r5, the open-source HAPI FHIR library's module of R5 model classes, because its example came from R5. The service talks to R4 servers. The R5 version management page says backward compatibility "is not guaranteed by FHIR." It also says R5 has not been submitted to the American National Standards Institute (ANSI) as a normative standard, and that for Trial Use content "there are no rules for maintaining any sort of compatibility between versions."

Normative content is locked and follows FHIR's rules for changes between versions; Trial Use content can still change without them. A resource built from R5 classes can carry elements an R4 server does not define.

It asks for every scope

SMART scopes say what an app may read or change. In version 2, patient/Observation.rs means read and search observations for one patient. The SMART scopes page says a wildcard such as patient/*.cruds asks for "all data for all available FHIR resources, both now and in the future." It tells clients to "avoid the use of wildcard scopes purely for the sake of convenience." An agent that hits a permission error during development has an easy fix: widen the scope. The error goes away, and the app now asks for far more than it needs.

The same page maps the older syntax to the new one: version 1 .read becomes .rs. An agent trained on both may write either.

It claims a profile instead of meeting it

A profile is a set of constraints on a resource, and US Core is a set of profiles. A resource can list the profiles it conforms to in meta.profile. The R4 resource page warns that a resource "may falsely claim to conform to a profile," and says conformance is settled "by testing it against the profile." An agent can add the US Core profile URL to a resource in one line. Adding the URL proves nothing.

It goes around the approved client

Suppose your team routes every FHIR call through one client module that holds the base URL, the token handling and the retry rules. An agent building a reporting job finds it simpler to call the server directly. It might start a bulk export, [fhir base]/Group/[id]/$export in the Bulk Data Access guide, from a request handler instead of the scheduled job the team built for it. The calls are valid FHIR, and they break this system's design.

Write the FHIR decisions down

A check needs something to check against. For FHIR work, that means writing each choice as an architecture decision record (ADR), a short document that records one decision and the reason for it. A useful first set:

  1. FHIR version. The integration targets R4 (4.0.1). No R5 model classes in this service.
  2. Implementation guide version. Which US Core version each endpoint is built and tested against, and who decides when to move.
  3. Scope policy. SMART version 2 syntax, the smallest scopes the feature needs, and no wildcards. SMART 2.0.0 lets a scope narrow to a category, for example patient/Observation.rs?category=http://terminology.hl7.org/CodeSystem/observation-category|laboratory for lab results only. Only search modifiers, chaining and _filter are marked experimental, and the guide has not yet fixed which search parameters every server must support, so check what yours supports.
  4. One client module. All FHIR calls go through it. No other module holds the base URL or a token.
  5. Where bulk export runs. Only the scheduled export job starts $export.
  6. Missing data. US Core marks some elements Must Support: a server must be able to send them, and a client must be able to process them. The Must Support rules also say that when such an element is missing from a resource, the client must read that as data the server does not have. The code must carry on without the element, not fail.

Even before any tool enforces them, these records give a reviewer, a new engineer and an agent the same answer to "which FHIR are we on?"

Which check catches which decision

The six decisions above do not fall to one kind of check. Some are prohibitions you can spot in the text of a change. Others need the resource itself, a running server or a test. In the table, a text rule is a check that fails a change containing an exact piece of text, optionally only in certain paths.

DecisionWhat a check looks forKind of check
FHIR versionThe R5 module name in a build fileText rule in CI and in the agent's hook
Scope policyWildcard scope strings in auth configurationText rule, plus review for scopes that are legal but too broad
One client moduleThe FHIR base URL outside the client moduleText rule limited to paths
Bulk export$export outside the export jobText rule limited to paths
Profile conformanceWhether a resource meets the US Core profile it claimsFHIR validator in CI
Missing dataBehavior when a Must Support element is absentTests with fixtures that omit elements

For conformance, the R4 validation page describes the FHIR Validator, a Java tool HL7 provides, which checks structure, cardinality, terminology bindings, invariants and profiles. It also says the validator "is only as good as the underlying definitions," so pin the guide version it loads to the one in your ADR. A FHIR server describes itself in a CapabilityStatement, a resource that, in the R4 specification's terms, documents what the server can do for a particular FHIR version. Its fhirVersion element names that version. An integration test can read it and fail when the server and the ADR disagree.

Where Mneme fits

Mneme enforces a team's architecture decisions on code changes, once each decision is written as a rule. From the table, it covers the FHIR version, one client module and bulk export rows, and the wildcard half of the scope policy row. It does not cover profile conformance or missing data.

Mneme 0.11.0 ships two typed rules. The one that fits these decisions forbids an exact, case-sensitive piece of text, optionally limited to certain paths. The other sets an upper limit on a number in Python code and does not apply here. For the decisions above, that means rules such as:

A decision with no such rule blocks nothing. Where a rule is active, it applies at two points.

While the agent works. In Claude Code, the Mneme plugin installs a hook, a script Claude Code runs around the agent's actions. When the agent edits a file with Claude Code's file tools (Edit, Write or MultiEdit) and the edit breaks a rule, the hook refuses it before the file changes. The hook also checks one shell form before it runs: a single cat > file <<'EOF' command with a quoted delimiter. When the agent writes a file through any other shell command, the hook checks the file at the end of the agent's turn, after it is written, and sends the agent back to fix it.

The hook fails open by default. If the check cannot run, for example because mneme is missing or the check takes longer than 10 seconds, the edit goes through.

In CI. The job described in Set up Mneme in CI only runs mneme check on every text file a pull request adds or modifies, and fails the pull request when one breaks an active rule. It blocks a merge only where you make it a required check, meaning a GitHub branch rule says the job must pass before anything merges. Deleted files, binary files and pushes that skip pull requests are not covered.

Mneme does not read FHIR. It cannot tell whether a resource meets a US Core profile, whether a scope without a wildcard is still too broad, or whether code handles a missing element. The FHIR Validator and your tests do that work. A required-presence rule, one that fails a change when something is missing, such as a profile URL on a resource, is on Mneme's roadmap and not shipped; the governance violations reference separates what is enforced today from what is not. For the prohibitions it does cover, Mneme gives the same verdict for the same change every time, whether an agent or a person wrote it.

To see where your own decisions stand, Mneme's Architecture Audit sorts a repository's recorded decisions into those a rule protects today and those that still depend on a reviewer.

The certification criteria listed at the start apply to certified health IT products, and the certification program assesses them. Nothing in this guide is a compliance claim. A text rule that keeps R5 classes out of an R4 service enforces your team's engineering decision, and that is all it shows.

A starting checklist

  1. Write the version ADRs first. FHIR version, US Core version and SMART version, each with an owner.
  2. Turn the prohibitions into rules. R5 module names, wildcard scopes, the base URL outside the client and $export outside the export job.
  3. Run the FHIR Validator in CI against the guide version your ADR names, on the resources your code builds.
  4. Test the server's CapabilityStatement in integration tests, and fail on a version mismatch.
  5. Protect the files that define these checks. Name owners for the ADRs, the rule files and the CI workflow in GitHub's CODEOWNERS file, and require those owners' review in a branch rule, so a change that loosens a check cannot merge without an owner's approval.

For the wider case, AI governance for regulated industries covers why provenance matters across regulated sectors, and AI coding agents in life sciences covers validation histories for life sciences software.

Frequently asked questions

Which FHIR version does US certification use?+
The certification companion guide for 45 CFR 170.315(g)(10) lists FHIR Release 4.0.1, US Core 6.1.0 and SMART App Launch 2.0.0 as the adopted standards, with newer US Core, SMART and Bulk Data versions approved as alternatives.
Is FHIR R5 compatible with R4?+
Not by guarantee. The R5 version management page says backward compatibility is not guaranteed by FHIR, and that Trial Use content has no rules for compatibility between versions. Treat the FHIR version as a decision and pin it.
Does adding a US Core profile URL make a resource conform?+
No. The R4 specification warns that a resource may falsely claim to conform to a profile, and says conformance is determined by testing the resource against the profile, for example with the FHIR Validator.
Can Mneme validate FHIR resources?+
No. The Mneme rules that fit FHIR work forbid exact text, optionally limited to paths, such as keeping wildcard SMART scopes out of auth configuration or R5 model classes out of an R4 service. Profile conformance belongs to the FHIR Validator and your tests.