Business · Product · Technology · AI

Enforce optional AI context at the construction boundary, before formatting

A Movo-X source-tracing case separating general AI consent, optional health-context consent, database context construction, provider formatting and withdrawal limits.

Work directly with Omer Muneer Qazi · Reviewed 29 November 2026

The scenario: using an assistant and sharing stored context are different choices

A person can choose to start an AI conversation without also choosing to supply existing health context. If an implementation treats one consent label as permission for every data source, the interface can imply more control than the request pipeline actually provides.

The inspected Movo-X code represents general AI-session consent and optional context consent separately. This walkthrough traces native request fixtures, route validation, selected pinned SQL and the provider formatter. The six scoped cases use synthetic inputs. The SQL was reviewed as source and was not executed against a real database.

Keep person scope separate from a clinic-scoped session

The selected native episode-start fixture creates a general session with a person identifier and the AI consent version. It checks the absence of clinic and clinic-patient selectors in that request and the chosen language and request identifier.

In that fixture, declining optional context causes its grant fields to be omitted. The request still carries the general AI consent version. This establishes the selected serialized shape; it does not prove that a user read a consent interface or that the real server authorized a particular caregiver to act for that person.

Require an explicit version for the optional grant

The route accepts the optional context grant only with its recognized context-consent version. The selected TypeScript fixture supplies a grant without that version and checks refusal before its database adapter is called, then checks the accepted versioned grant forwarded to the adapter.

The route also exposes a separate consent-toggle operation with a Boolean granted value. The fixture checks selected malformed input and withdrawal forwarding. This is an input contract for the route, not a legal assessment or a live demonstration that the authoritative consent state changed.

Locate the authoritative context decision in the pinned SQL

The inspected SQL records optional context-consent metadata on the session. In the reviewed message-reservation branch, it attempts to build structured person context only when that session has recorded consent and a person identifier. The later feedback migration retains that condition in its replacement function.

The context builder selects named categories from its health projection and returns category names alongside the context. The selected context-log insert records those categories rather than copying the entire context values into that log entry. This is not a whole-system logging audit, and a migration file does not establish the functions currently installed in production. A change to the selected context categories should therefore trigger a data-flow review alongside ordinary schema and prompt changes.

Do not mistake a type adapter for a disclosure filter

The TypeScript personContext adapter checks that its input is an object rather than an array or null. Its type permits additional keys, and the prompt formatter serializes the supplied object within its selected text bound. It does not independently look up consent or enforce a field-by-field privacy allow-list.

The supplemental fixture adds a synthetic extra field and checks that it remains in formatted output. That makes the responsibility visible: context construction and eligibility belong upstream. Adding a new field to the database projection or introducing another caller needs review at that boundary instead of assuming the formatter will silently remove it.

Prompt framing is an instruction, not proof of clinical behaviour

The formatter labels supplied context as potentially incomplete or outdated and as data rather than instructions. The existing prompt fixture checks selected caregiver and context-framing text. It does not evaluate a real model’s clinical accuracy, resistance to every embedded instruction or interpretation of every source fact.

A bounded serialized context also does not guarantee that every original field reaches the provider intact. Separate tests should cover any required field-preservation contract. This chapter makes no claim that a passing prompt-string assertion validates medical advice, diagnoses or the completeness of a person’s record.

Withdrawal concerns future context construction, not erasing earlier delivery

The reviewed toggle updates the session’s context-consent metadata, and later message-reservation logic uses that state when deciding whether to construct context. These are the source-level steps relevant to subsequent work. No live withdrawal transaction or concurrent provider operation was tested.

An earlier request may already have constructed or delivered context before withdrawal. This source review therefore does not claim retroactive deletion, recall of provider input or atomic cancellation of all in-flight work. Those are separate lifecycle and data-handling requirements that need an explicit protocol and evidence if the product promises them.

A useful context-consent acceptance package

Keep native request-shape, route refusal/forwarding and formatter-boundary cases distinct from database permission and transaction tests. Record the source revision and installed-function evidence separately. Test concurrent withdrawal and in-flight work only against the precise behaviour the product intends to promise.

For a CTO, the result is a data-sharing path with named ownership: the client expresses a choice, the route validates its representation, the authoritative layer selects eligible context and the formatter renders what it receives. The current source and six scoped cases explain those boundaries without claiming a complete privacy or clinical acceptance programme.

Compare the reviewed boundaries

Where optional context decisions belong

On smaller screens, scroll across to compare every column. Keyboard users can focus the table and use the arrow keys.

LayerEvidence in this caseSeparate acceptance
Native requestDistinct general and optional-consent fieldsActual user choice and person authority
API routeVersioned grant and selected toggle validationAuthoritative persisted state
Pinned SQL constructionConsent-conditioned context selection in sourceInstalled functions and concurrent withdrawal
Provider formatterSerializes supplied object with framingUpstream field minimization and real model behaviour

Illustrative control flow

Pseudocode summarizing the decision boundary. It is not copied production code or a deployment instruction.

request = express_session_consent_and_optional_context_choice()
validate_recognized_grant_version(request)

on_authoritative_message_reservation:
    context = build_selected_context_only_if_session_eligible()

provider_body = format_supplied_context(context)

# Formatting is not the consent authority or a retroactive deletion mechanism.

About this engineering series

Written by Omer Muneer Qazi from a review of Movo-X implementation and dated engineering records. This article explains source behaviour and historical observations; current production, clinical outcomes and store availability require their own verification. Examples are synthetic and proposed test cases are identified as such.

Explore the Movo-X engineering series → · Related implementation experience →

Discuss a similar engineering problem

Send the workflow, current platform and the decision your team needs to make. I can help define an implementation or review scope with concrete acceptance evidence.

Discuss your project on WhatsApp ↗
WhatsApp Omer about this project ↗