Intercept: Middleware Guardrails for Laravel AI Agents
Developers integrating AI into Laravel applications should read this to learn about Intercept, a package offering middleware that protects against prompt injection and PII exposure in the Laravel AI SDK.
It provides an easy way to add security guardrails before sending prompts to providers.
Intercept, created by Victor Ukam for the Laravel AI SDK, introduces a middleware pattern for AI prompts. Positioned between the agent and the AI provider, it allows developers to inspect, rewrite, or reject prompts before they leave the application. It is designed as an additional security layer rather than a replacement for existing input validation or access controls.
The package currently provides two primary guardrails. The PromptInjectionGuard uses regular expressions to detect manipulation attempts, such as instructions to ignore previous prompts. Developers can choose to block the request, log the event, warn the user, or sanitize the content. Advanced usage allows for custom callbacks to log detections or prepend specific instructions to the prompt.
To protect user privacy, the PIIRedactor identifies structured personal data, including emails, phone numbers, IP addresses, API keys, bearer tokens, and credit cards (via Luhn check). Depending on the configuration, it can mask, redact, log, or block the prompt. By default, highly sensitive data like credit cards and API keys trigger an immediate block unless configured otherwise.
Intercept requires PHP 8.4 and the laravel/ai package. While it currently ships at version 0.1.4, the roadmap includes future expansions into observability, performance, and guidance. Configuration can be handled per agent via the HasMiddleware interface or globally through a published config file.
Readers’ Forum
No contributions yet — open the debate.
Open the discussion
No account or password needed — just enter your e-mail and we’ll send you a one-time sign-in link. First time here? You’re set up automatically.
Your rating will be applied automatically after you sign in.
Check your inbox
We’ve sent a sign-in link to …. Open it on this device — this tab will sign you in automatically.
Waiting for your click …
·