Download the PHP package yannelli/schematic without Composer
On this page you can find all versions of the php package yannelli/schematic. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yannelli/schematic
More information about yannelli/schematic
Files in yannelli/schematic
Package schematic
Short Description Database-driven templating language with JSON Schema generation for LLM structured outputs
License MIT
Informations about the package schematic
Schematic
- Introduction
- Installation
- Configuration
- JSON Schema Defaults
- Custom Models
- Creating Templates
- Adding Sections
- Defining Fields
- Array & Object Fields
- Ephemeral Templates
- Creating Ephemeral Templates
- Ephemeral Schema & Rendering
- JSON Schema Generation
- Template Schemas
- Section Schemas
- Using With Anthropic
- Using With OpenAI
- Managing Sections
- Enabling & Disabling Sections
- Reordering Sections
- Iterating Sections
- Adding & Removing Fields
- Rendering Templates
- Full Template Rendering
- Previewing With Examples
- Template Syntax
- Custom Macros
- Extending Models
- License
Introduction
Schematic is a templating engine for Laravel that generates JSON Schema definitions from your templates. It is designed for use with LLM structured output APIs such as those provided by OpenAI and Anthropic, allowing you to define templates with typed fields and automatically produce valid JSON Schema for tool use and structured responses. Templates can be persisted to the database or created as ephemeral (in-memory) templates for on-the-fly use without any database overhead.
Installation
Install Schematic via Composer:
After installing, publish and run the migrations:
You may optionally publish the configuration file:
Configuration
The Schematic configuration file is located at config/schematic.php. Each configuration option is documented below.
JSON Schema Defaults
The schema options control the defaults used when generating JSON Schema output:
| Option | Environment Variable | Default | Description |
|---|---|---|---|
schema.draft |
— | https://json-schema.org/draft/2020-12/schema |
The JSON Schema draft URI included in schema documents. |
schema.strict |
— | true |
When enabled, all generated schemas include additionalProperties: false. |
Custom Models
If you need to extend the base Schematic models, you may specify your custom model classes in the models configuration array. See Extending Models for details.
Creating Templates
To create a new template, use the Schematic facade's create method:
Adding Sections
Once a template has been created, you may add sections to it using the addSection method. Each section defines a portion of the template with its own content, fields, and optional example data:
Defining Fields
Each field in a section requires a name, type, and description. You may also specify whether the field is required or nullable:
When a field's type is set to enum, you should provide an enum array containing the allowed values. Fields are required by default; set required to false and nullable to true for optional fields.
Array & Object Fields
For more complex data structures, you may define fields with array and object types. Array fields require an items key describing the structure of each element:
Ephemeral Templates
Ephemeral templates are in-memory templates that are not persisted to the database. They are useful for one-off or dynamic templates that you build at runtime — no migrations or database queries required.
Ephemeral templates support the same core features as database-backed templates: sections, fields, JSON Schema generation, rendering, and previewing.
Creating Ephemeral Templates
Use the ephemeral method on the Schematic facade to create an in-memory template:
You may also create ephemeral templates directly via the EphemeralTemplate class:
Sections on ephemeral templates support the same fluent methods as database-backed sections, including addField, removeField, enable, disable, and setExamples. All mutations happen in memory.
Ephemeral Schema & Rendering
Ephemeral templates generate JSON Schema and render content exactly like their database-backed counterparts:
Section management works identically — you can iterate, reorder, enable, and disable sections:
JSON Schema Generation
Schematic generates JSON Schema definitions from your templates, ready for use with LLM structured output APIs.
Template Schemas
To generate a JSON Schema for an entire template, use the toJsonSchema method on a template instance. For a full schema document including the $schema header, use toJsonSchemaDocument:
Section Schemas
You may also generate a schema for a single section:
The generated schema for the mental-status-exam section would look like the following:
Using With Anthropic
To use a Schematic template with the Anthropic API, pass the generated schema as a tool's input_schema:
Using With OpenAI
When using OpenAI's structured output, pass the schema document to the response_format parameter:
[!NOTE] OpenAI's structured output requires the full schema document (via
schemaDocument), while Anthropic's tool use expects the schema object (viaschema).
Managing Sections
Enabling & Disabling Sections
You may enable or disable individual sections on a template. Disabled sections are excluded from both schema generation and rendering:
Reordering Sections
To change the order in which sections appear, pass an array of section slugs to the reorderSections method:
Iterating Sections
To iterate over a template's sections, use the iterateSections method. By default, only enabled sections are returned in their defined order:
To include disabled sections, use iterateAllSections:
Adding & Removing Fields
You may add or remove fields from an existing section:
Rendering Templates
Full Template Rendering
To render a template with data, pass an associative array keyed by section slug to the render method:
Previewing With Examples
When you have defined example data on your sections, you may preview the rendered output without providing data manually. To set example data on a section, use the setExamples method:
To preview a single section or the entire template using its example data:
Template Syntax
Schematic provides a lightweight template syntax for defining section content:
| Syntax | Description |
|---|---|
{{ variable }} |
Variable substitution. |
{{ nested.key }} |
Dot-notation access for nested values. |
@if(var) ... @endif |
Conditional block; renders content only when var is truthy. |
@if(var) ... @else ... @endif |
Conditional with an else branch. |
@foreach(items as item) ... @endforeach |
Iterate over an array. |
@macroName("arg1", "arg2") |
Invoke a registered custom macro. |
Custom Macros
You may register custom macros to extend the template syntax. Macros should be registered in a service provider's boot method:
Once registered, macros may be used in any template content:
Extending Models
If you need to add custom behavior to the Schematic models, you may extend the base Template and Section classes and register them in the configuration:
Your custom models should extend the corresponding base classes:
Credits
- Ryan Yannelli
- Nextvisit AI
- All Contributors
License
Schematic is open-sourced software licensed under the MIT license.
All versions of schematic with dependencies
illuminate/database Version ^12.0 || ^13.0
illuminate/support Version ^12.0 || ^13.0