Date: 2026-03-23
This checkpoint marks the current codebase changes as part of a repo-wide LLM schema refactor rather than a set of isolated feature patches.
The goal of this refactor is to move structured LLM output handling onto a shared foundation:
- shared schema definitions per domain
- shared structured invoke / repair flow
- provider capability awareness for JSON output
- less ad-hoc
JSON.parse + try/catch + local normalizationscattered across services
This batch touches multiple domains at the same time:
- planner
- novel core / chapter summary
- world / world visualization / world reference
- audit
- book analysis
- character
- genre
- style detection
- title generation
- Creative Hub and route entry points
Because the change is horizontal and architectural, a normal feature note is not enough. Future changes should recognize this commit as a migration checkpoint for the overall LLM schema layer.
New shared entry points have been introduced under server/src/llm/:
structuredInvoke.tsschemaHelpers.ts
These files centralize:
- structured output invocation
- JSON extraction
- truncated JSON repair
- Zod validation
- one-step repair retry through LLM when schema validation fails
server/src/llm/capabilities.ts now acts as the capability gate for provider/model JSON behavior, instead of leaving each service to guess whether a model supports forced JSON output.
This is intended to become the single place that answers:
- whether a provider supports
json_object - whether a provider supports schema-level JSON output
- whether a specific model family needs extra guarding
Schema files are being extracted from business services into dedicated schema modules, including but not limited to:
server/src/services/audit/auditSchemas.tsserver/src/services/bookAnalysis/bookAnalysisSchemas.tsserver/src/services/character/characterSchemas.tsserver/src/services/genre/genreSchemas.tsserver/src/services/novel/chapterSummarySchemas.tsserver/src/services/novel/novelCoreSchemas.tsserver/src/services/planner/plannerSchemas.tsserver/src/services/state/stateSchemas.tsserver/src/services/title/titleSchemas.tsserver/src/services/world/worldSchemas.tsserver/src/services/world/worldReferenceSchema.tsserver/src/services/world/worldVisualizationSchema.ts
The intended direction is:
- business services own prompts, orchestration and persistence
- schema modules own structured output contracts
Several services have been moved away from domain-local LLM parsing helpers and toward the shared schema/invoke path. This is visible in book analysis, planner, novel core, title generation, world-related services, style detection and related route wiring.
This checkpoint should be treated as:
- an in-progress architectural migration
- not the final stable end state
- suitable to commit as a milestone boundary
What is already true:
- the repo now has a visible shared LLM schema layer
- multiple domains have started migrating onto it
- provider capability handling is no longer fully scattered
What is not fully finished yet:
- some old normalization paths still coexist with the new schema path
- not every service has been migrated to the same strictness level
- some schema files are intentionally tolerant and will still need tightening after more real-output validation
After this checkpoint, new LLM-facing development should prefer:
- define or extend a schema module first
- route generation through shared structured invoke
- keep deterministic cleanup as post-processing only
- avoid adding new one-off JSON parsing branches inside business services
If a later change needs structured output in a new domain, it should build on this layer instead of reintroducing local ad-hoc parsing.
This checkpoint exists so the current code can be recognized later as:
- the start of the repo-wide LLM schema migration
- a deliberate architectural boundary
- a safe point for continued migration in later commits