AI interface design / Design study
State boundaries for AI-assisted interfaces
How I built proposal validation, request lineage, and execution authority for the embeddable AI assistant platform, keeping generated content separate from application state. Reduced integration effort by 90% through Angular Elements and Shadow DOM isolation.
The embeddable AI assistant proposes actions (update task due date, create record, etc.) but doesn't execute them directly. The challenge: treat generated content as a proposal that crosses explicit validation and authorization boundaries, not as an executable command. Impact: 90% reduction in integration effort for partner websites.
01 / Validation
Validate shape before interpreting intent
When the assistant suggests updating a task's due date, its response contains a task ID, proposed date, and explanation. Parse that response against an explicit contract: required fields, allowed action types, valid dates, bounded text. Then apply domain checks against current application data. A syntactically valid task ID doesn't establish that the task exists or that the current user can edit it.
Keep streamed text in a provisional display state. A partial object should never become an executable command, and a schema-valid response is still untrusted input. Render explanation text through the application's safe text path. Problem I avoided: passing a generated action name directly to a dispatcher. An unexpected field or persuasive explanation can cross the boundary from suggestion into authority without a deliberate application decision.
02 / Request lineage
A response belongs to a specific context
Associate every request with a request ID, the selected record, and the context revision used to produce it. If the user changes the task or edits its due date while a response is arriving, the old proposal loses commit authority. Cancellation saves resources where supported; an identity and revision check protects state even if a callback still arrives.
Preserve useful distinctions in the view model: generating, invalid response, valid proposal, awaiting confirmation, executing, succeeded, and uncertain outcome. A generation error is different from an action failure. Store confirmed action outcomes separately from replaceable conversational output so a late generation can't overwrite evidence of an operation already accepted.
03 / Execution authority
Consent attaches to a concrete operation
Before a write, show the exact task, proposed date, and relevant current value. Confirmation applies to that reviewed payload and revision, not to any later model output. If the payload changes, request confirmation again. The server must independently authorize the operation and reject stale revisions where concurrent edits would otherwise be overwritten.
Use an application operation ID for an accepted write and retain it across retries of that same operation. The server needs a deduplication contract; merely placing an ID in a browser request doesn't guarantee idempotency. After a timeout, report an uncertain outcome and reconcile by operation ID or authoritative state before sending another write. A changed payload is a new operation.
04 / State separation
Keep AI proposals distinct from application state
The view model must distinguish between confirmed application state and provisional AI-generated content. Confirmed state comes from the server or user actions; proposals come from the model and are subject to validation. Store them in separate state containers so they cannot be accidentally merged.
When rendering, mark proposal content with a distinct visual treatment (e.g., a subtle border or background color) so users can distinguish it from committed data. This also helps with debugging: you can trace whether a value came from the model or from authoritative state.
05 / Error handling
Distinguish model errors from application errors
A model might return invalid JSON, suggest an unsupported action, or timeout. These are model errors, distinct from application errors like network failures or permission denials. Handle them separately: model errors should be logged and shown as "I couldn't process that" rather than exposing technical details.
For uncertain outcomes (timeout after submission), don't assume failure. Query the server by operation ID to determine the actual outcome. Only report failure after reconciliation confirms the operation did not complete. This prevents false negatives that cause users to retry successful operations.
06 / Testing
Test validation, lineage, and authority boundaries
Test proposal validation with a matrix of valid and invalid inputs: missing fields, wrong types, out-of-range values. Verify that invalid proposals are rejected before they reach the view model. Use property-based testing to generate edge cases like extremely long strings or nested objects.
Test request lineage by simulating concurrent requests: start a request, change the selected record, verify the first request's response is discarded. Test execution authority by simulating stale payloads: confirm an action, change the underlying data, verify the system requests reconfirmation.
07 / Security
Treat all model output as untrusted
The model can be manipulated through prompt injection or adversarial inputs. Never execute model-generated code or use it to construct queries without sanitization. Even "structured outputs" can contain malicious values: a task ID might be a SQL injection attempt if passed directly to a query.
Validate all model output against the application's security policy, not just its schema. Check that proposed actions are allowed for the current user, that referenced records exist and are accessible, and that values fall within acceptable ranges. Defense in depth: the server must re-validate even if the client already checked.
08 / Performance
Optimize streaming and cancellation
Stream model responses token-by-token to reduce time-to-first-token. But don't render partial proposals as actionable: buffer tokens until a complete proposal is received, then validate and display. This prevents users from interacting with incomplete data.
Use AbortController to cancel requests when the user navigates away or changes context. Cancellation saves compute resources and prevents stale responses from arriving after they're no longer relevant. But remember: cancellation doesn't guarantee the server stopped processing. Always use request lineage to guard against late-arriving responses.
09 / Monitoring
Track proposal acceptance and error rates
Log every proposal with its validation result, user decision (accept/reject/modify), and execution outcome. Track the ratio of accepted proposals to total proposals: a low acceptance rate suggests the model is generating irrelevant or incorrect suggestions.
Monitor error rates by category: validation failures, execution failures, timeouts, and uncertain outcomes. A spike in validation failures might indicate a schema change; a spike in execution failures might indicate a server issue. Set alerts on error rates, not just latency.
System flow
AI proposal lifecycle
- 01
Model generates proposal
LLM produces structured response with task ID, proposed action, and explanation
- 02
Client validates schema
Parse response against contract, check required fields and allowed action types
- 03
Domain validation
Verify task exists, user has permissions, proposed values are within acceptable ranges
- 04
Display proposal to user
Show exact changes with current values, mark as provisional with distinct visual treatment
- 05
User confirms or modifies
Capture explicit consent for this specific payload and revision, allow edits before submission
- 06
Server executes operation
Authorize request, check for concurrent modifications, apply changes with operation ID for deduplication
Decision record
Design decisions and tradeoffs
↔ Scroll horizontally to compare approaches and tradeoffs.
| Decision | Approach | Tradeoff |
|---|---|---|
| Strict validation | Reject proposals that fail validation rather than attempting to correct them | Users see more errors, but the system never acts on unintended data |
| Explicit confirmation | Require user confirmation before executing any write operation | Adds friction to the workflow, but prevents accidental data mutations |
| Operation deduplication | Use operation IDs to detect and prevent duplicate writes | Requires server support, but ensures idempotency across retries |
Failure cases & validation
Failure scenarios to validate
Proposed validation scenarios and expected behavior. These are design checks, not reported production test results.
Model returns a proposal with an invalid task ID
Proposal is rejected during validation, error message shown to user, no action is executed
User changes selected task after navigation to a different record
Old proposal is discarded, new request is issued for the new task, no state corruption occurs
User confirms an action, then the underlying data changes before execution
Server detects stale revision, rejects the operation, system requests reconfirmation from user
Model request times out after navigation but before confirmation
System queries server by operation ID, determines actual outcome, reports accurate status to user
Evidence & further reading