PHPackages                             ykachala/guardrails - 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. [Security](/categories/security)
4. /
5. ykachala/guardrails

ActiveLibrary[Security](/categories/security)

ykachala/guardrails
===================

Input/output safety layer for PHP LLM apps: PII redaction, prompt-injection detection, secret scanning, and content moderation as a composable pipeline.

00PHP

Since Jun 2Pushed 1mo agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Ykachala Guardrails
===================

[](#ykachala-guardrails)

> A composable input/output safety layer for PHP applications that call LLMs. Redact PII before it leaves your server, catch prompt-injection and jailbreak attempts, scan for leaked secrets, and moderate model output — all in one pipeline.

[![PHP Version](https://camo.githubusercontent.com/5a2eb3f6217f798b7ca58d59764e8fd3d779752c0cef2b8634034d9e7e4ba92d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e332d373737626234)](https://www.php.net/)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)

---

Why this exists (the 2026 gap)
------------------------------

[](#why-this-exists-the-2026-gap)

The PHP AI ecosystem grew up fast in early 2026 — **Prism PHP**, **Neuron AI**, and the official **Laravel AI SDK** now cover the *happy path*: making calls, RAG, agents, and structured output. What none of them own is the **safety boundary**.

In the Python world this is a solved, well-funded problem: **LiteLLM** guardrails and **pydantic-ai-shields** ship PII filtering, prompt-injection defense, and secret redaction out of the box. PHP teams shipping AI to production in 2026 have **no native equivalent** — they either roll fragile regexes by hand or proxy everything through a Python sidecar.

Ykachala Guardrails closes that gap with a framework-agnostic, provider-agnostic safety pipeline that sits between your app and *any* LLM client.

What it does
------------

[](#what-it-does)

GuardStageWhat it catches`PiiGuard`input + outputEmails, phones, SSNs, credit cards, IBANs, IPs — **reversibly tokenized** so you can restore them after the round-trip`InjectionGuard`input"Ignore previous instructions", role-override, delimiter-escape, and encoded jailbreak patterns (heuristic + optional LLM classifier)`SecretGuard`input + outputAPI keys, bearer tokens, private keys, `.env`-shaped values`ModerationGuard`outputToxicity, banned topics, configurable category thresholds`SchemaGuard`outputRejects responses that break an expected shape before they reach usersEach guard returns a **verdict** (`allow` / `redact` / `block`) with a reason, so you decide the policy: fail closed, fail open, or sanitize-and-continue.

Install
-------

[](#install)

```
composer require ykachala/guardrails
```

Quick start
-----------

[](#quick-start)

```
use Ykachala\Guardrails\Pipeline;
use Ykachala\Guardrails\Guard\PiiGuard;
use Ykachala\Guardrails\Guard\InjectionGuard;
use Ykachala\Guardrails\Guard\SecretGuard;

$pipeline = Pipeline::make()
    ->input(new InjectionGuard(action: 'block'))
    ->input(new SecretGuard(action: 'block'))
    ->input(new PiiGuard(action: 'redact'))   // reversible
    ->output(new PiiGuard(action: 'restore')); // put real values back

// 1. Sanitize what you send to the model
$safe = $pipeline->inbound($userMessage);
if ($safe->blocked()) {
    throw new UnsafeInputException($safe->reason());
}

$response = $yourLlmClient->chat($safe->text());

// 2. Sanitize what you show the user
$clean = $pipeline->outbound($response, context: $safe);
echo $clean->text();
```

### Reversible PII tokenization

[](#reversible-pii-tokenization)

```
// "Email john@acme.com about order 4111-1111-1111-1111"
$safe = $pipeline->inbound($text);
// -> "Email  about order "   (sent to the model)

$restored = $pipeline->outbound($modelReply, context: $safe);
// model's "" placeholders are swapped back to john@acme.com
```

Framework bridges
-----------------

[](#framework-bridges)

- **Laravel** — `GuardrailsServiceProvider`, config publish, and a `guarded()` macro on the Prism/Laravel-AI pending request.
- **Symfony** — a `GuardrailsBundle` with a tagged-service guard registry and middleware.
- **Vanilla** — the `Pipeline` is pure PHP with zero framework deps.

Architecture
------------

[](#architecture)

```
src/
├── Pipeline.php            # orchestrates inbound/outbound passes
├── Verdict.php             # allow | redact | block + reason + redaction map
├── Guard/
│   ├── GuardInterface.php
│   ├── PiiGuard.php
│   ├── InjectionGuard.php
│   ├── SecretGuard.php
│   └── ModerationGuard.php
├── Detector/               # low-level detectors (regex + pluggable ML)
└── Bridge/                 # Laravel + Symfony integration

```

Roadmap
-------

[](#roadmap)

- Core pipeline + verdict model
- Regex detector pack (PII, secrets) with locale-aware rules
- Heuristic injection detector + optional LLM classifier adapter
- Reversible tokenization store
- Laravel &amp; Symfony bridges
- Pluggable model-based detectors (toxicity, semantic PII)

See [`CLAUDE.md`](CLAUDE.md) for the full phase plan and conventions.

License
-------

[](#license)

MIT

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance59

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c5892a06b5cc3a1f6adaa3fa3d0cb5e9f77c6fc613425df614e2c4778b2e0a7?d=identicon)[joel767443](/maintainers/joel767443)

---

Top Contributors

[![ykachala](https://avatars.githubusercontent.com/u/985991?v=4)](https://github.com/ykachala "ykachala (6 commits)")

---

Tags

aianthropicguardrailslaravelllmmoderationopenaipiiprompt-injectionsecuritysymfony

### Embed Badge

![Health badge](/badges/ykachala-guardrails/health.svg)

```
[![Health](https://phpackages.com/badges/ykachala-guardrails/health.svg)](https://phpackages.com/packages/ykachala-guardrails)
```

###  Alternatives

[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k18.7M144](/packages/mews-purifier)[paragonie/ecc

PHP Elliptic Curve Cryptography library

24820.0k41](/packages/paragonie-ecc)

PHPackages © 2026

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