Drupal is a registered trademark of Dries Buytaert
Release: Leaflet 10.4.11 Minor update available for module leaflet (10.4.11). Release: Session Inspector 1.0.8 Minor update available for module session_inspector (1.0.8). Release: Migrate QA 2.0.4 Minor update available for module migrate_qa (2.0.4). Release: CKEditor Description List 3.0.0 Major update available for module ckeditor_descriptionlist (3.0.0). Release: FlowDrop 2.4.0 Minor update available for module flowdrop (2.4.0). Release: JWT Token Refresh 1.0.4 Minor update available for module jwt_token_refresh (1.0.4). Release: ConReg 1.0.0-beta1 First beta version released for module conreg (1.0.0-beta1). Release: AI Image Studio 1.0.0-beta8 New beta version released for module ai_image_studio (1.0.0-beta8). Usage Milestone: Role Theme Switcher Module role_theme_switcher crossed 1,000 active installs. Module Revived: Decoupled Router 2.0.7 Module decoupled_router updated after 11 months of inactivity (2.0.7).

This Drupal recipe installs AI guardrails to protect public AI interactions from malicious input and harmful requests. It uses a combination of regular expressions and AI topic classification to prevent injection attacks and filter out sensitive or risky topics like legal or medical advice before they are processed by AI.

A Drupal recipe that installs a set of AI guardrails to protect public-facing AI interactions from two distinct categories of risk: structurally malicious input (injection attacks) and semantically harmful requests (topics with legal or reputational exposure). Apply this recipe as a baseline safety layer on any site where the AI module processes untrusted user input.

What This Recipe Does

This recipe installs ten individual guardrails and two guardrail sets into a Drupal site running the AI module.

Guardrail Set: Prompt Safety — Security

Contains seven guardrails applied to the pre-generate phase (user input). It covers two layers of protection:

  • Regex-based (six guardrails): fast, zero-cost checks that detect structurally malicious strings such as <script> tags, inline event handlers, javascript: URLs, dangerous HTML tags, CSS expression injection, and JavaScript execution function calls.
  • AI-based (one guardrail): topic classification that detects semantic prompt manipulation like jailbreak attempts, system prompt overrides, and role hijacking, where rigid patterns are insufficient because attack phrasing constantly evolves.

Guardrail Set: Prompt Safety — Liability

Contains three guardrails applied to the pre-generate phase (user input). All three use AI topic classification to detect requests covering domains where an automated response creates legal or reputational risk for the site operator:

  • Legal Advice: contract interpretation, litigation strategy, regulatory compliance.
  • Medical Advice: diagnosis, treatment recommendations, medication guidance.
  • Sensitive Topics: politically and socially divisive subjects (elections, religion, war, etc.).

When to use this recipe:

  • Any public-facing AI interaction (chatbots, AI assistants, content generation tools)
  • Sites where users can submit free-text prompts that reach an AI provider
  • Environments that need a documented, auditable safety baseline before deploying AI features

Requirements

  • Drupal 11.2 or later
  • drupal/ai ^1.3
  • A configured AI provider that supports topic classification (required by the four restrict_to_topic guardrails)

How to Apply

Run the following Drush command from your Drupal root:


drush recipe ../recipes/ai_recipe_guardrails_prompt_safety 

The recipe does not configure a specific AI provider or model. The restrict_to_topic guardrails will use whichever provider and model your site has set as the default for the AI module.

Configuration Installed

Guardrail Sets

Machine name Label Guardrails included Phase prompt_safety_security Prompt Safety: Security 7 (see below) Pre-generate prompt_safety_liability Prompt Safety: Liability 3 (see below) Pre-generate

Stop threshold for both sets: 0.8

Guardrails

Machine name Label Plugin security_script_tag_injection Security: Script Tag Injection regexp_guardrail security_dangerous_html_tags Security: Dangerous HTML Tags regexp_guardrail security_html_event_handler_injection Security: HTML Event Handler Injection regexp_guardrail security_javascript_protocol Security: JavaScript Protocol regexp_guardrail security_javascript_execution_functions Security: JavaScript Execution Functions regexp_guardrail security_css_expression_injection Security: CSS Expression Injection regexp_guardrail security_prompt_manipulation Security: Prompt Manipulation restrict_to_topic liability_legal_advice Liability: Legal Advice restrict_to_topic liability_medical_advice Liability: Medical Advice restrict_to_topic liability_sensitive_topics Liability: Sensitive Topics restrict_to_topic

Activity

Tracked releases
1
Tracked since
Mar 2026
Latest release
5 months ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Active

Releases

Version Type Release date
1.0.0 Stable Mar 23, 2026