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

acquaintsoft logo
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech

The latest

View all →
Slow Job Alerts and Replica Commit IDs in Laravel 13.40 image

Slow Job Alerts and Replica Commit IDs in Laravel 13.40

Read article
Flock: A Free, Native Herd Alternative for Laravel image

Flock: A Free, Native Herd Alternative for Laravel

Read article
Live Props for Real-Time Updates in Inertia.js v3.11 image

Live Props for Real-Time Updates in Inertia.js v3.11

Read article
Cooldown Dependency Policy now in Composer 2.11 image

Cooldown Dependency Policy now in Composer 2.11

Read article
Email Sending and Testing for Laravel in One Account image

Email Sending and Testing for Laravel in One Account

Read article
Decide with Jev: Tie Every AI Check to the Exact Draft image

Decide with Jev: Tie Every AI Check to the Exact Draft

Read article