> ## Documentation Index
> Fetch the complete documentation index at: https://intercept.promptphp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Handling blocked prompts

Some Intercept middleware actions stop a prompt before it reaches the AI provider.

When a prompt is blocked, your app should catch the exception and return a safe user-facing response.

## Injection Guard exception

Injection Guard throws:

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
PromptPHP\Intercept\InjectionGuard\Exceptions\PromptInjectionGuardException
```

Example:

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
use PromptPHP\Intercept\InjectionGuard\Exceptions\PromptInjectionGuardException;

try {
    $response = SupportAgent::prompt($message);
} catch (PromptInjectionGuardException) {
    return response()->json([
        'message' => 'Your message could not be processed because it appears to contain unsafe prompt instructions.',
    ], 422);
}
```

## PII Redactor exception

PII Redactor throws:

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
PromptPHP\Intercept\PIIRedactor\Exceptions\PIIRedactorException
```

Example:

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
use PromptPHP\Intercept\PIIRedactor\Exceptions\PIIRedactorException;

try {
    $response = SupportAgent::prompt($message);
} catch (PIIRedactorException) {
    return response()->json([
        'message' => 'Your message could not be processed because it appears to contain sensitive data.',
    ], 422);
}
```

## Catch both exceptions

Most apps should catch both.

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
use PromptPHP\Intercept\InjectionGuard\Exceptions\PromptInjectionGuardException;
use PromptPHP\Intercept\PIIRedactor\Exceptions\PIIRedactorException;

try {
    $response = SupportAgent::prompt($message);
} catch (PromptInjectionGuardException) {
    return response()->json([
        'message' => 'Your message could not be processed because it appears to contain unsafe prompt instructions.',
    ], 422);
} catch (PIIRedactorException) {
    return response()->json([
        'message' => 'Your message could not be processed because it appears to contain sensitive data.',
    ], 422);
}
```

<Tip>
  You may also catch the parent exception class `InterceptException` throwable by all Intercept middleware.
</Tip>

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
use PromptPHP\Intercept\Support\Exceptions\InterceptException;

try {
    $response = SupportAgent::prompt($message);
} catch (InterceptException $exception) {
    return response()->json([
        'message' => 'Your message could not be processed because it appears to contain unsafe prompt instructions or sensitive data.',
    ], 422);
}
```

## Validation-style responses

If your frontend expects validation errors, return a validation-style payload.

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
return response()->json([
    'message' => 'The given data was invalid.',
    'errors' => [
        'message' => [
            'Please remove unsafe instructions or sensitive data and try again.',
        ],
    ],
], 422);
```
