fr3on/laravel-guardrail

Enterprise-grade input/output safety & compliance layer for AI agents.

Maintainers

Package info

github.com/fr3on/laravel-guardrail

pkg:composer/fr3on/laravel-guardrail

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

0.0.1 2026-04-12 11:13 UTC

This package is auto-updated.

Last update: 2026-04-12 11:14:49 UTC


README

Latest Version on Packagist GitHub Tests Action Status Total Downloads PHP Version Support Laravel Version Support License

Laravel Guardrail is an enterprise-grade input/output safety & compliance layer for the Laravel AI SDK. It acts as a firewall for your AI agents, ensuring that both user inputs and LLM responses adhere to your security, privacy, and domain policies.

Features

  • Input Guarding: Block prompt injections, redact PII (Personally Identifiable Information), and enforce input length constraints.
  • Output Guarding: Prevent topic drift, toxicity, system prompt leakage, and PII leakage in LLM responses.
  • AI SDK Middleware: Seamlessly hooks into the native Laravel AI SDK agent middleware system.
  • Violation Logging: Automatically persists safety violations for auditing and fine-tuning.
  • Zero Configuration: Sensible defaults that work out of the box with standard Laravel configurations.

Installation

You can install the package via composer:

composer require fr3on/laravel-guardrail

You can publish the config file with:

php artisan vendor:publish --tag="guardrail-config"

Usage

Register the Guardrail middleware in your Laravel AI SDK agent:

namespace App\Ai\Agents;

use Fr3on\Guardrail\Middleware\Guardrail;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Contracts\HasMiddleware;

class CustomerSupportAgent implements Agent, HasMiddleware
{
    public function middleware(): array
    {
        return [
            new Guardrail([
                // Input rules
                'prompt_injection' => 'block',
                'pii_redaction' => 'redact',
                
                // Output rules
                'toxicity' => 'retry',
                'topic_drift' => 'fallback',
            ]),
        ];
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.