Forerunner for Laravel is a package that provides a migration-inspired API for defining JSON schemas that ensure your LLM responses are perfectly structured every time. Define structured output schemas for LLMs using Laravel's familiar migration syntax:
use Blaspsoft\Forerunner\Schema\Struct;use Blaspsoft\Forerunner\Schema\Property; $schema = Struct::define('User', 'A user schema', function (Property $property) { $property->string('name', 'The user\'s full name')->required(); $property->string('email', 'The user\'s email address')->required(); $property->int('age', 'The user\'s age')->min(0)->max(150); $property->boolean('is_active', 'Is the user account active?')->default(true);})->toArray();
The above struct returns an array, and can also be converted to JSON:
{ "type": "object", "properties": { "name": { "type": "string", "description": "The user's full name" }, "email": { "type": "string", "description": "The user's email address" }, "age": { "type": "integer", "description": "The user's age", "minimum": 0, "maximum": 150 }, "is_active": { "type": "boolean", "description": "Is the user account active?", "default": true } }, "description": "A user schema", "required": [ "name", "email" ], "additionalProperties": false}
Main Features
- Define structured output schemas for LLMs
- Multiple field types available: String, Integer, Float, etc.
- Helper methods for commonly used field formats
- String format validation
- Ensure field array items are unique
- Strict mode for LLM APIs
- Define schema metadata
- And more
This package is currently a pre-release version, but we thought it was interesting enough to share. The API may change; plan accordingly.
💻 You can get started with this package on GitHub: Blaspsoft/forerunner