Skip to main content
The clinician states a clinical fact: a symptom, a vital, an allergy, a diagnosis. The agent turns it into a structured record, a documentation suggestion that is not saved until the clinician confirms. Each clinical family has its own schema tool, and the agent picks the one matching the fact.
Extract flow: the clinician states a clinical fact, the agent classifies it, codes the concepts, and emits a structured suggestion. The clinician confirms before it is saved.Extract flow: the clinician states a clinical fact, the agent classifies it, codes the concepts, and emits a structured suggestion. The clinician confirms before it is saved.

A clinical fact becomes a structured suggestion. The clinician confirms before it is saved.

Before you start

Build a schema tool

Each step adds one part of a schema tool. The example is an allergy: the clinician says “Allergic to penicillin, hives.” and the agent emits a coded allergy record for the clinician to confirm.
1

Start from the connector body

A schema tool is a request body you post. It is a schema-tool create body (CommonSchemaConnectorCreate in the v2 API) with five fields:
  • type is always "schema". It tells the framework this connector is a tool you define.
  • name is how the agent and your system prompt refer to the tool.
  • description is prose the model reads to decide when and how to call the tool.
  • schema is plain JSON Schema, the same shape tool definitions use across the LLM ecosystem. It is the complete contract for what the agent may emit.
  • transition is the agent’s exit state after it calls the tool.
The next steps fill in each field, using the allergy example.
2

Name the tool and write its description

Name the tool after the one thing it emits, and put the tool’s rules in the description. The model reads this string every time it decides whether to call the tool, so rules written here travel with the tool to every agent that uses it.
Each sentence carries one rule: what input the tool takes, how to code concepts, how to record onset, how many records per call, and that the output is a suggestion.
3

Close the object and mark what is required

The top level of schema is an object with additionalProperties: false. The agent can then emit only the fields you defined, nothing invented. required lists the fields every suggestion must carry. Fields not in required, such as criticality, are filled only when the clinician says them.
Give the record a resourceType field that can hold only one value. A const allows exactly one value, so every record this tool emits carries "resourceType": "AllergyIntolerance". The client reads that field to know what kind of record it received, for example to choose which write API to call. The field sits in properties next to the other fields:
text is the record’s short summary in plain words, such as “Penicillin allergy”.
4

Model the coded concepts

The allergen and each reaction’s manifestation are coded concepts. The allergen field is named code, and it holds four fields:
  • system names the terminology the code belongs to, as a URI. http://snomed.info/sct is SNOMED CT.
  • code is the identifier in that terminology, so the allergen’s identifier sits at code.code.
  • display is the code’s human label.
  • text keeps what the clinician said, for when the code is less precise than their words.
Only display is required. That is deliberate: the agent can always record what the clinician said, even when no code resolves, and your apply-step decides what to do with an uncoded concept. system is a const here because the coding connector resolves SNOMED CT. Widen it to an enum if your EHR uses more than one terminology.reaction is an array. Each reaction holds a manifestation array of the same coded-concept object, with at least one item, and an optional severity.
5

Constrain values with enums

Wherever a field accepts a fixed set of values, use an enum. The agent then picks from that set instead of writing free text that your apply-step has to interpret.
clinicalStatus is whether the allergy is current, and verificationStatus is how certain it is. criticality is the risk of a future severe reaction. How severe a past reaction was goes in that reaction’s severity (mild, moderate, or severe), so “mild rash as a child, anaphylaxis last year” keeps both. If the clinician calls an allergy severe or life-threatening without naming a reaction, the agent sets criticality to high.
6

Choose the transition

transition is the agent’s exit state after it calls the tool:
  • complete: the agent is done. Extract uses this because the suggestion is the whole result.
  • input_required: the agent yields and waits for the client to send something back, such as the EHR data in Retrieve patient data.
The framework enforces both the schema and the transition.
7

Attach it with the coding connector

Coding a concept needs a coding tool, so attach the coding-expert registry connector in the same connectors array as the schema tool. See Medical Coding.
Include the connectors when you create the agent, as shown in Create and configure an agent, or POST them to the connector sub-resource, as shown in Manage connectors.

The full body

The agent sets at most one of the three onset fields. Only an exact date or age the clinician said goes into onsetDateTime or onsetAge. Anything relative or vague, such as “three years ago” or “in her forties”, stays in onsetString in the clinician’s words. The agent never calculates a date.

Point the system prompt at the tools

The schema tools define what the agent can emit. The system prompt routes each request to the right tool. For extract, the hardest routing decision is the family: the agent must pick one of the family tools, not emit a mix. A minimal prompt only needs the routing:
Add the rules every flow shares to this prompt. Extract is the flow likeliest to break the last of them, “Never report a record as saved”. With transition: complete, the agent’s output looks finished to a client that is not watching for the seam, so the prompt must keep “suggestion” distinct from “saved”. If suggestions go straight into the record, check that the client treats an extract_ call as a proposal, not a write, before adding prompt rules. For more on writing a systemPrompt, see Create and configure an agent.

Run it

The agent handles a stated fact in one response: it classifies the family, codes the concepts, and emits the record. The system prompt and the tool descriptions produce this sequence.
1

Clinician states a fact

“Allergic to penicillin, hives.”
2

Classify the family

The agent routes the fact to extract_allergy.
3

Code the concepts

The agent uses coding-expert to resolve the allergen and the reaction to coded concepts.
4

Emit the structured record

The agent calls extract_allergy and ends in complete. The record is pending confirmation, not yet saved.
The agent emits this suggestion. “Hives” resolves to the SNOMED CT concept whose preferred term is “Wheal”: display records the concept, not the clinician’s phrasing. code.text stays empty because the code is as precise as what the clinician said.
Nothing is saved yet. The client shows the suggestion, and when the clinician confirms, it adds the patient reference and anything else your EHR needs, then writes the record through your EHR’s write API. The schema’s contract is a coded concept (system, code, display, text), not a particular code system, so you can swap the coding connector or the terminology.

The other families

Allergy is one of seven families, and they fall into three shapes, so do not assume one schema fits all of them. Each family is its own schema tool, built with the same parts as allergy. Build one schema per family. The fields shown are the minimum we recommend, but your EHR may need more. The wrapper families carry no resourceType, because every item a wrapper tool emits is the same kind of record.
Flat object, resourceType is const: Condition. The coded-concept fields are code and bodySite[]. Whether the record is a diagnosis or a finding is carried by the SNOMED CT code itself, so the schema needs no field for it.
  • category says where the record belongs: problem-list-item (the patient’s ongoing problem list) or encounter-diagnosis (a diagnosis for this visit).
  • clinicalStatus adds recurrence, relapse, and remission to the allergy set, and verificationStatus adds provisional and differential.
  • The side of the body goes into the body-site code, such as a SNOMED CT concept for the left knee. When the code is less precise, its text keeps what the clinician said, such as “left knee”.
  • use* marks a chief complaint (CC) or an admission diagnosis (AD). The client copies it onto the visit record.
  • severity is a SNOMED CT concept limited to Severe, Moderate, and Mild, and is left out when the clinician gives none.
  • Onset follows the same exact-or-text rule as allergy. abatementDateTime, abatementAge, and abatementString record when the condition ended, follow the same rule, and apply only when clinicalStatus is resolved, inactive, or remission.
* Differs slightly from FHIR R4, where a simpler field is easier for the agent to fill.
Flat object, resourceType is const: FamilyMemberHistory. One record describes one relative, and that relative’s conditions go in condition[]. Each condition has a coded code, an optional contributedToDeath, and an onset as onsetAge or onsetString, following the same exact-or-text rule as allergy.
  • relationship takes standard family-member codes, such as MTH (mother), FTH (father), MGRMTH (maternal grandmother), and HSIS (half-sister). FAMMEMB (family member) covers a relative no closer code fits.
  • name tells apart two relatives with the same relationship, such as two sisters.
  • deceasedBoolean or deceasedAge records that the relative has died, at most one of them.
  • dataAbsentReason records why the history is missing, such as subject-unknown when the patient is adopted and the family history is unknown.
  • verificationStatus* records doubt, such as “not sure if dad had diabetes”.
  • Family history has no clinicalStatus and no asserter.
* Differs slightly from FHIR R4, where a simpler field is easier for the agent to fill.
Each pregnancy or breastfeeding fact is one item, identified by a fixed LOINC code. The tool emits items[], one item per fact, and each item takes exactly one value field:The two status answers are LOINC answer codes, so the tool needs no coding connector. verificationStatus* applies only to the two status items. performer records who stated the fact, with the same values as asserter on allergy. A pregnancy or labor admission is a Condition with use: ["AD"], extracted with extract_diagnosis.* Differs slightly from FHIR R4, where a simpler field is easier for the agent to fill.For “She’s 8 weeks pregnant, second pregnancy, one previous birth, LMP was 1 October 2026”, the agent emits four items. It does not calculate an estimated delivery date.
Array wrapper {language, items[]}. language is the language of the input, such as en. Each item has a coded code and exactly one value: valueQuantity, a number with its unit, or valueString for a result that is not a number, such as “positive” or “trace”. Scores (GCS, pain) have no unit. Blood pressure is two items, systolic and diastolic.The codes are SNOMED CT*, because Medical Coding resolves SNOMED CT.* Differs slightly from FHIR R4, which suggests LOINC codes for observations.Units are written as the clinician said them. If a measurement needs a unit and the clinician did not say one, the agent asks instead of guessing. To store units in a standard form, your application can map unit to UCUM, a widely used unit standard.
Array wrapper {language, items[]}. Each item is a Task with a required description, an optional dueDate*, and an optional priority (routine, urgent, asap, or stat). The client adds the task’s status and intent.* Differs slightly from FHIR R4, where a simpler field is easier for the agent to fill.
Notes wrapper {notes[]}. Each note carries plain-text content, an optional date, and an optional description (the note’s title). The agent writes only words, and the client encodes content for storage.

Adapt it

Map each record to your EHR’s write API in your apply-step where its names differ. Widen a system const to an enum if your EHR uses more than one terminology, then attach each body to your agent. Add a schema tool for any clinical family you expose. The seven above cover the families this recipe walks through, not an exhaustive list. The transition is complete on every family: the agent emits a suggestion and stops, pending confirmation.