Guardrail Schema v1 Implementation Checklist
Goal
Implement Guardrail Schema v1 in the current orchestrator flow with minimal architectural change, using existing plan and block schema validation primitives. Primary implementation file:apps/orchestrator/src/index.ts
packages/shared/src/index.ts
Function Anchors (Current Code)
runChatPipeline(...)applyOpsAtomically(...)toErrorDetail(...)isNoEffectiveChangeError(...)clarificationSuggestions(...)app.post("/ops", ...)app.post("/chat", ...)app.get("/chat/stream", ...)- Shared schemas:
blockSchemasoperationSchemaeditPlanSchemavalidateBlockProps(...)
Phase 1: Error Taxonomy Wiring
1. Add typed error categories
Location:apps/orchestrator/src/index.tsnear existing error helpers (toErrorDetail,isNoEffectiveChangeError).
- Introduce internal error category type:
schema_violationambiguitynot_foundno_effective_changeinternal_error
- Add
classifyGuardrailError(reason: string)helper. - Add
formatValidationError(category, message, fieldPath?)helper for consistent UI-facing errors.
- Every known validation/apply failure can be classified deterministically.
2. Standardize chat failure payload mapping
Location:runChatPipeline(...)catch paths and final failure return.
- Replace raw
validationErrors: [outcome.reason]with classified messages. - Keep current wire format:
status: "validation_error"validationErrors: string[]
- Preserve
needs_clarificationpath for ambiguity.
/chatand/chat/streamfinal error payloads contain categorized, consistent messages.
Phase 2: One-Retry Deterministic Auto-Repair
3. Constrain retry budget from generic attempts to bounded repair
Location:runChatPipeline(...)planning/apply loop.
- Keep planning attempts as needed, but allow only one guardrail repair pass after apply failure.
- Add
isDeterministicRepairEligible(reason: string)helper. - Add
buildRepairFeedback(reason)to request strictly structural fixes only. - Ensure no semantic rewrite hints are injected into repair prompt.
- At most one structural repair attempt occurs per request after initial failure.
4. Enforce stopping rules
Location:runChatPipeline(...)retry loop and post-loop fallback.
- Stop immediately for non-repairable/ambiguous failures.
- On failed repair, return:
needs_clarificationfor ambiguityvalidation_errorfor schema violations
- Keep existing preview version invariants (no bump on rejected edits).
- The pipeline never enters unbounded or semantic-rewrite retries.
Phase 3: Operation/Props Guardrail Hardening
5. Improve field-level diagnostics in apply layer
Location:applyOpsAtomically(...)and helper branches (update_props,add_item,update_item, etc.).
- Preserve current hard-blocking behavior.
- Upgrade thrown errors to include field context where possible:
- block id/type
- prop key/list key/index
- Keep unknown prop protection in
update_propsbranch.
- Validation failures identify specific fields (not only generic “Invalid props for X”).
6. Keep block schema authority in shared package
Location:packages/shared/src/index.ts
- Confirm v1 constraints match current
blockSchemas. - Add comments for intentionally permissive fields (e.g.
RichText.title). - Do not expand into policy/a11y/SEO constraints in v1.
- Shared schema remains the single source of truth for field constraints.
Phase 4: Endpoint Contract Consistency
7. /chat and /chat/stream parity
Location:
app.post("/chat", ...)app.get("/chat/stream", ...)
- Ensure stream
finalpayload mirrors/chatpayload for:appliedneeds_clarificationvalidation_error
- Keep
op_appliedbehavior unchanged. - Ensure
errorstream event includes categorized validation messages when available.
- Non-stream and stream clients get equivalent guardrail outcomes.
8. /ops endpoint alignment
Location:
app.post("/ops", ...)
- Keep strict payload validation via
operationSchema. - Optionally add
errorCodein response while preserving existingerrorstring for compatibility. - Ensure
/opsrejects never mutate state or bump version.
- Direct ops path has guardrail behavior consistent with chat pipeline.
Phase 5: Acceptance Test Matrix
9. Add tests for required v1 scenarios
Location:- Existing orchestrator tests (add new suite if needed in
apps/orchestrator/src).
- Valid apply:
- update Hero heading
- add FeatureGrid item
- Hard-block failures:
- missing required prop on add/update
- unknown
op - invalid index on item ops
- Clarification:
- ambiguous prompt ->
needs_clarification
- ambiguous prompt ->
- Auto-repair:
- one deterministic repair succeeds
- non-repairable case stops and returns expected failure
- Invariants:
- rejected change does not bump
previewVersion - rejected change does not persist mutations
- rejected change does not bump
- All scenarios pass and map to v1 spec outcomes.
Implementation Order (Recommended)
- Error taxonomy helpers
- Retry/repair constraints in
runChatPipeline - Field-level diagnostic improvements in
applyOpsAtomically - Endpoint parity checks (
/chat+ stream +/ops) - Acceptance tests
Out of Scope for v1
- Section-aware composition constraints
- Per-customer policy profiles
- Tone/claim/SEO/accessibility policy enforcement
- Multi-user conflict policy