Back to projects
Maintained

Schematic

A Laravel templating engine that builds JSON Schema from your templates. Made for LLM structured-output APIs like OpenAI and Anthropic.

  • Laravel
  • PHP
  • JSON Schema
  • LLM
  • AI
  • OpenAI
  • Anthropic

The problem

Working with LLM structured outputs means writing JSON Schema by hand for every shape you want the model to return. That’s fine for one or two endpoints. It falls apart when you have dozens of prompts, each with their own response shape, and the schemas live somewhere different from the code that consumes them. The schemas drift, validation breaks at runtime, and every prompt change becomes a coordinated edit across multiple files.

The same problem also shows up backwards: you have business templates that need to be filled by LLM output, and you want the template itself to dictate what the model returns. Writing the template in one place and a matching schema in another is duplication you’ll regret.

What Schematic does

Schematic is a Laravel templating engine that produces valid JSON Schema as a first-class output. You define the shape once, in a Schematic template, and you can render either the filled-in text or hand the matching schema straight to OpenAI or Anthropic’s structured-output APIs.

Templates can live in the database for runtime editing by non-developers, or exist purely in memory for one-off use. Typed fields (string, integer, boolean, enum, array, object) become typed JSON Schema properties. Conditional blocks, loops, and custom macros let templates handle real business logic without falling back to string concatenation. Sections can be enabled, disabled, and reordered without rewriting the template, which matters when you’re driving generation from admin UI rather than code.

Why it exists

This came out of the Nextvisit codebase. Behavioral health documentation has dozens of clinical note shapes (SOAP, DAP, BIRP, addiction-treatment specifics) and each one needs to be a valid schema the LLM can target precisely. Maintaining schema files alongside Blade templates was already painful before we added a second LLM provider; once we did, the duplication got intolerable. Schematic was the abstraction we wished existed.

It’s open-source because the underlying problem isn’t specific to behavioral health: anyone building production LLM pipelines in PHP runs into this. The package is on Packagist as yannelli/schematic.