← Wiki

SGR — schemas first, logic second, UI last

2026-04-07 concept sgrschemasdddpydanticzodmethodology

Schema-Guided Reasoning (SGR): all projects built from schemas to logic, not the other way around. Schemas are the contract between AI agent, business logic, and UI.

Order: Define domain (typed schemas) → Then logic (services work with schemas) → UI last (displays schemas, doesn’t parse strings).

When an AI agent works on a project, it MUST:

SGR is the technical implementation of DDD:

By stack: Pydantic (Python), Zod (TypeScript), SwiftData @Model (iOS), data class + kotlinx.serialization (Kotlin).

BAML extends SGR for LLM output: when you need structured responses from LLMs, BAML turns prompt engineering into schema engineering. Use SGR (constrained decoding) where precision matters (tool routing, classification), BAML where reasoning matters (extraction, analysis).