PHPackages                             fr3on/laravel-guardrail - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. fr3on/laravel-guardrail

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

fr3on/laravel-guardrail
=======================

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

0.0.1(3mo ago)1228MITPHPPHP ^8.2CI passing

Since Apr 12Pushed 3mo agoCompare

[ Source](https://github.com/fr3on/laravel-guardrail)[ Packagist](https://packagist.org/packages/fr3on/laravel-guardrail)[ RSS](/packages/fr3on-laravel-guardrail/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

Laravel Guardrail
=================

[](#laravel-guardrail)

[![Latest Version on Packagist](https://camo.githubusercontent.com/510dbfe5faa4b1f955a78bd154267e0b823a8b1dce3bd6c2db2ea661555f1818/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6672336f6e2f6c61726176656c2d67756172647261696c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fr3on/laravel-guardrail)[![GitHub Tests Action Status](https://camo.githubusercontent.com/51fe6c6cf2f41c59388df38e66c0c712abfefc7c88a5d7d7bfad3184027173b8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6672336f6e2f6c61726176656c2d67756172647261696c2f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/fr3on/laravel-guardrail/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/549f87f65455d9c2fdae1cee118df9c079b1988fc90156298429aaa39da7f70e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6672336f6e2f6c61726176656c2d67756172647261696c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fr3on/laravel-guardrail)[![PHP Version Support](https://camo.githubusercontent.com/112fdc9102cd1bcea532ede480d2f0b15e4a61b8a1bedacce41efc5d52ba5d89/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322d3838393262662e7376673f7374796c653d666c61742d737175617265)](https://www.php.net/)[![Laravel Version Support](https://camo.githubusercontent.com/8a72c4d04b68a3090c6e58daed3f9e27dba8c532b98c482605351f3458c0b2b0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d253545313025374325354531312d6666326432302e7376673f7374796c653d666c61742d737175617265)](https://laravel.com/)[![License](https://camo.githubusercontent.com/d9a9d402e7df9715649a10b290cc59009bdc8931e8bfba461d7b046ddf3a404c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6672336f6e2f6c61726176656c2d67756172647261696c2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

**Laravel Guardrail** is an enterprise-grade input/output safety &amp; 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
--------

[](#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
------------

[](#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
-----

[](#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
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Ahmed Mardi](https://github.com/fr3on)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance80

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

103d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/205356416?v=4)[fr3onv](/maintainers/fr3onv)[@fr3onv](https://github.com/fr3onv)

---

Top Contributors

[![fr3on](https://avatars.githubusercontent.com/u/26393383?v=4)](https://github.com/fr3on "fr3on (8 commits)")

---

Tags

aicomplianceinputlaraveloutputphpsafetylaravelaiinputoutputcompliancesafety

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/fr3on-laravel-guardrail/health.svg)

```
[![Health](https://phpackages.com/badges/fr3on-laravel-guardrail/health.svg)](https://phpackages.com/packages/fr3on-laravel-guardrail)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M246](/packages/laravel-ai)[elegantweb/sanitizer

Sanitization library for PHP and the Laravel framework.

1151.1M3](/packages/elegantweb-sanitizer)[sandermuller/laravel-fluent-validation

Fluent validation rule builders for Laravel

20720.5k4](/packages/sandermuller-laravel-fluent-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
