Download the PHP package muyki-labs/laravel-guardrails without Composer

On this page you can find all versions of the php package muyki-labs/laravel-guardrails. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-guardrails

Laravel Guardrails

Tests PHPStan Latest Version

A safety layer for LLM input and output in Laravel. Laravel Guardrails validates, sanitizes, and (optionally) blocks the data flowing in and out of language models so teams can ship AI features that are compliant and predictable — PII redaction, prompt-injection detection, moderation, and schema validation behind one fluent, composable pipeline.

It is provider-agnostic and ships with zero required external services: regex PII detection, heuristic prompt-injection and moderation, and Laravel-validation-backed schema checks all work out of the box. Every detector is a pluggable, extend()-able manager, so you can swap in an NER service, an OpenAI moderation driver, or an LLM-as-judge without touching call sites.

Installation

Publish the config:

If you want the persisted audit log, publish and run the migration:

Requires PHP 8.3+ and Laravel 12 or 13.

The pipeline

Guardrails::for($value) returns a fluent pipeline. Chain guards, then terminate with one of:

Input guards

Method What it does
stripPII(array $types = [], ?string $strategy = null) Redact detected PII. Strategy: mask, hash, tokenize, remove.
blockPromptInjection() Flag jailbreak / instruction-override attempts.
maxTokens(int $max) Reject (or truncate) input over a token budget.
maxLength(int $max) Reject (or truncate) input over a character length.
allow(array $terms) Require the input to mention at least one allowed term.
deny(array $terms) Reject input that contains a denied term.

Output guards

Method What it does
validateSchema(array\|Closure $rules) Validate decoded JSON/array against Laravel rules or a callback.
blockToxic() / moderate() Run moderation over the output.
noPII(array $types = []) Fail if the model echoed PII back.

Custom guards

Wrapping an LLM call

Guardrails::pipe() wraps any callable: input guards run before the call, output guards after. With the retry strategy a rejected output re-invokes the model.

The callable is provider-agnostic, so it works with Prism, laravel/ai, or your own client. Input violations always fail closed (they cannot be "retried"); only output guards drive the retry loop.

Violation strategies

Set per pipeline with onViolation() (default comes from config('guardrails.default_strategy')).

Policies

Named, reusable guard sets live in config/guardrails.php:

PII detection & redaction

The built-in regex detector recognises email, phone, IBAN, Luhn-checked credit card, Turkish national ID (TCKN, checksum-validated), and IPv4. Patterns and the enabled types are configurable under guardrails.pii. Redaction strategies:

Register a custom detector (e.g. an NER provider):

The moderation and prompt-injection subsystems work the same way via ModerationManager::extend() and InjectionManager::extend().

Events

Bind to any of these (e.g. for audit logging, dashboards, or alerting):

Event Fired when
GuardrailPassed A pipeline completes with no hard violations.
GuardrailViolated One or more guards reported a violation.
InputRedacted An input guard sanitized the value (e.g. PII redaction).
OutputBlocked An output pipeline reported a violation.
GuardrailRetried The LLM wrapper re-ran the call under the retry strategy.

Audit log

Set guardrails.audit.enabled to true to persist violations for a compliance trail (KVKK / GDPR). Drivers: database (queryable), log (writes to the Laravel logger), or null.

Enable scheduled pruning under prune.schedule in the config.

Commands

Testing

License

The MIT License (MIT). See LICENSE.md.


All versions of laravel-guardrails with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/console Version ^12.0 || ^13.0
illuminate/contracts Version ^12.0 || ^13.0
illuminate/database Version ^12.0 || ^13.0
illuminate/support Version ^12.0 || ^13.0
illuminate/validation Version ^12.0 || ^13.0
nesbot/carbon Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package muyki-labs/laravel-guardrails contains the following files

Loading the files please wait ...