Laravel Packages

Define LLM JSON Schemas in Laravel With Forerunner

Published
Define LLM JSON Schemas in Laravel With Forerunner image

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

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
Generate Laravel Validation Rules From a JSON Schema image

Generate Laravel Validation Rules From a JSON Schema

Read article
Laravel Suspicious Login: Detect and Block Risky Logins image

Laravel Suspicious Login: Detect and Block Risky Logins

Read article
Decide with Jev: Make Failed AI Requests Safe in Laravel image

Decide with Jev: Make Failed AI Requests Safe in Laravel

Read article
Black Friday: Learn the habits behind AI workflows that work image

Black Friday: Learn the habits behind AI workflows that work

Read article
Laravel Black Friday and Cyber Monday Deals 2026 image

Laravel Black Friday and Cyber Monday Deals 2026

Read article
pgjumbo: A PostgreSQL Client for macOS, Windows, and Linux image

pgjumbo: A PostgreSQL Client for macOS, Windows, and Linux

Read article