Looking to hire Laravel developers? Try LaraJobs

laravel-guardrail maintained by fr3on

Description
Enterprise-grade input/output safety & compliance layer for AI agents.
Author
Ahmed Mardi
Last update
2026/04/12 13:13 (dev-main)
License
Links
Downloads
228

Comments
comments powered by Disqus

Laravel Guardrail

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.