fr3on / laravel-guardrail
Enterprise-grade input/output safety & compliance layer for AI agents.
0.0.1
2026-04-12 11:13 UTC
Requires
- php: ^8.2
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- laravel/pint: ^1.0
- orchestra/testbench: ^8.0|^9.0|^10.0
- pestphp/pest: ^2.34|^3.0
README
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.