AI · model routing · schema-constrained output · audit
Charles Trinh — AI Service Layer

A governed AI service layer for healthcare workloads: model routing, schema-constrained output, audit logging and the boundary between automation and clinical judgement.
What this is
An AI service layer is the piece between a clinical workflow and a model, and its whole job is to make the model behave predictably in the places a care organisation can actually predict: the shape it returns, the money it spends, the record it leaves, and the route it takes when a vendor goes down.
Most teams start with the prompt and discover the layer later, usually after the first incident. The prompt is the least stable part of the system. The layer is the part you can test, budget, pin and switch off, which is why it should be designed before the prompt is tuned.
It is also where governance stops being a policy document. A model inventory, an intended-use statement and an evaluation record only mean something if the layer enforces the version, records the decision and can refuse to run. This page is about building that layer rather than describing it.
Where AI belongs in a clinical stack
Automate the deterministic steps around judgement, never the judgement itself, and keep a named human accountable for anything that reaches a record.
The practical test is the reverse of the usual one: ask what happens when the model is confidently wrong, and whether a person would see it before it lands. If the answer is no, the step is not ready to automate, however good the demo looked.
Routing and fallback
A single provider is a single point of failure; route by task class with a declared fallback and a recorded reason for each switch.
The route is also a cost control. Extraction, summarisation and drafting have very different price and latency profiles, and sending all three to the largest model is a choice that shows up on the invoice long before it shows up in quality.
Schema-constrained output
A model returning free text pushes the reading cost back onto the clinician; a validated schema returns something a system can act on.
The schema is a contract with the downstream system, so it is validated at the layer, not trusted from the model. Shape first, then types, then domain rules such as code sets and date ranges, because each layer catches a different class of error.
Audit logging
Log the input, output, model version and the decision taken, so six months later the record can be reconstructed rather than remembered.
What is logged is itself a decision: identifiers may need hashing, free text may contain PHI, and the retention window should match the investigation window you actually need. Decide that once, at the layer, instead of per integration.
Cost and latency budgets
Per-request cost is a design constraint; a workflow that is elegant and unaffordable is a prototype wearing production clothes.
Set a budget per task class and enforce it at the layer with a hard stop, not a dashboard. The first month of real traffic usually reveals one workflow quietly consuming most of the spend, and it is rarely the one anyone expected.
Failure semantics
Decide what happens when the model is unavailable, slow or wrong, and make that behaviour visible rather than silent.
A degraded mode that returns an empty field is worse than an error, because the workflow continues and the gap is discovered by someone reading a chart. Timeouts, retries and refusal all need a defined, recorded outcome.
Data boundaries
What may leave the boundary is a policy question; the architecture should make the wrong choice difficult, not merely discouraged.
That means one egress point with an allow-list, redaction before the call rather than after, and a record of every payload that crossed. A vendor BAA answers who is liable; it does not answer what was sent.
Governance questions
Who is accountable for this output, what happens when it is wrong, and how would we know.
Those three questions belong on a one-page statement per model, written before launch and revisited when the version changes. A model with no answers is not governed, however thorough the policy that mentions it.
How I do it
I start with one workflow that already has a cost of being wrong: a document intake, a summarisation step, a triage queue. I trace it end to end and name every place a model output reaches a person, which usually turns up two or three steps nobody had listed.
Then the layer is built around those steps: a schema per task, a route per task class, a budget per task class and an audit record per request. The model choice is deliberately the last decision, because it is the one most likely to change and the least likely to be the thing that failed.
The engagement ends with the layer failing on purpose. I make a provider unavailable, make a model return malformed output and make it return a confident wrong answer, and we watch the workflow behave as specified. That exercise is the delivery.
Artifacts you keep
- A routing table by task class with declared fallback and recorded switch reasons
- A validated output schema per task, with domain-rule checks after the type checks
- An audit record per request: input hash, output, model version, decision, latency, cost
- A per-task budget with a hard stop and a monthly cost report by workflow
- A one-page governance statement per model, dated and owned
The boundary the layer enforces
A service layer earns its name by being the only place a model is called. Routing, retries, schema validation, redaction and audit happen there, and every application that wants a model goes through it. When a second team embeds a provider SDK directly, the boundary has failed and the failure is invisible until an audit asks which prompts left the estate.
Keeping the boundary means making the layer easier than the alternative: one client, one credential, one schema, one log. Where the layer is slower or less convenient than a direct call, teams route around it, and no policy prevents that.
Cost and the routing decision
Routing is a cost and latency decision as much as a quality one. A classification task does not need the largest model, and a summarisation task does not need one that emits reasoning it will never be shown. Recording the task type with the routing decision turns a cost review into a query rather than an argument.
Track cost per task type and per tenant monthly. The pattern that matters is a task silently upgraded to a bigger model because someone changed a default, which produces a bill increase nobody can attribute to a decision.
What the audit needs to contain
For each call: the requesting identity, the task type, the model, the prompt class, the token counts, the outcome and the latency. The prompt content itself belongs in a separate store with its own retention, because the audit needs to answer who called what kind of thing, not to archive clinical text forever.
Retain the audit for the period the disclosure obligations imply, and the payloads for a shorter period with a documented justification. A pipeline that keeps everything forever is a liability that grows silently.
Evaluation before deployment
A task moves from pilot to production when its error rate is measured against a labelled set and someone with clinical authority accepts the residual. That sentence is the whole governance requirement, and it is what an examiner will ask for when the question is how the organisation decided the output was fit for use.
Re-run the evaluation on every model or prompt change, because the evaluation is a property of a version rather than of a system. Teams that evaluate once and deploy repeatedly are measuring a system that no longer exists.
W
here the layer meets procurement
A
service layer is also the negotiating position. When every model call passes through one component, switching provider is a configuration change rather than an application rewrite, and the cost of leaving becomes knowable. That is worth building even when no switch is planned.
R
ecord the exit test: one task routed to a second provider, measured for quality and latency. An untested second provider is an assumption, and assumptions are priced by the counterparty.
What to build first
One client, one credential, one log, one schema. That is a week of work and it is the foundation every later decision depends on, because routing, cost control and audit all need a single choke point to exist.
Everything else — evaluation harnesses, provider failover, tenant quotas — is easier once the choke point is in place, and considerably harder before it.
Proof
- ONC (g)(10) self-test PASS, 317 of 317 subtests, April 2026 — public suite URL
- 67 public hostnames, 51 serving, one AWS account
- 104 clearinghouse enrolments across 53 jurisdictions
- USCDI v7 proposal — Patient Digital Identity Credential — listed at isp.healthit.gov
- SAM.gov UEI MVKQW9DKKGB8 · CAGE 20KM5 · NPI 1194645564
- AWS Business Associate Addendum active since 18 August 2026
Where this work is delivered
Engagements run from Las Vegas and reach across the valley: clients in Las Vegas, NV; Las Vegas, Nevada; Henderson; Clark County, Nevada; and North Las Vegas, Nevada, plus remote delivery nationwide.
How an engagement runs
1. Trace one real case
Follow a single patient or claim end to end with a timestamp at every hop, before any document is written.
2. Written findings
A findings list naming the defect, the system, the owner and the date.
3. Monthly review
Review the list monthly and check whether the dates held.
Frequently asked
What is this service?
This page describes charles trinh — ai service layer — the scope, the failure modes it prevents and how the work is measured. It sits in the AI and Automation category at trinh.io.
Where is the work delivered?
Engagements run from Las Vegas, Nevada across the valley — Las Vegas, Henderson, North Las Vegas, Spring Valley, Paradise, Winchester, Sunrise Manor, Enterprise, Summerlin, Clark County — and remotely anywhere in the United States. On-site work in the Las Vegas valley, remote delivery elsewhere.
What does it cost?
Standard rate $195 per hour, committed $165 per hour at twenty hours or more per week for three months or more; $1,600 standard day, $1,350 committed day. Scoped in writing before work starts, fixed fee where the deliverable is defined.
Who is Charles Trinh?
A technology architect in Las Vegas, Nevada, working in healthcare identity, consent and interoperability. Not a physician, not a medical practice, and not affiliated with any other Charles Trinh.
How does an engagement start?
With one trace of a real case and a written findings list naming the defect, the system, the owner and the date. The first call is twenty minutes and free: 702-559-3489.
Engagement
Scoped in writing before work starts; fixed fee where the deliverable is defined. First call is 20 minutes and free. 702-559-3489 · charles@trinh.io
Talk to Charles
- Phone: 702-559-3489
- Email: charles@trinh.io
- Based in Las Vegas, Nevada · working remotely across the United States