[Tracker]
Update Summary: [One-line status update for stakeholders]
Short Description: Add Input Length Limit guardrail plugin
Check-in Date: MM/DD/YYYY
[/Tracker]
Problem/Motivation
There is currently no guardrail to limit the length of user input sent to AI providers. Excessively long inputs can be used for context stuffing attacks, denial-of-wallet attacks (consuming expensive API tokens), or to overwhelm the AI model's context window.
A simple input length limit guardrail would provide a configurable safety net that blocks requests exceeding a character or token count before they reach the provider API.
Proposed resolution
- Create a new
InputLengthLimitguardrail plugin that implementsprocessInput(). - Allow configuring a maximum length in characters, with an option to use the
ai.tokenizerservice for token-based counting instead. - The limit should apply to the last user message by default, with a configurable option to apply to the total conversation length (all messages combined).
- Return a
StopResultwhen the input exceeds the limit, with a configurable violation message. - Add tests covering both character-based and token-based limits.
AI usage (if applicable)
[x] AI Assisted Issue
This issue was generated with AI assistance, but was reviewed and refined by the creator.
[ ] AI Assisted Code
[x] AI Generated Code
[ ] Vibe Coded
- This issue was created with the help of AI
Issue fork ai-3582856
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
marcus_johansson commentedComment #4
marcus_johansson commentedGenerated using the following skill: #3582575: Add agent skill and drush generator for Guardrail plugins
Results:


Comment #5
marcus_johansson commentedThis also found that schemas was not correctly set and fixed it, I should probably split that up though, since its a bug and should be ported back.
Comment #6
ahmad khader commentedComment #7
ahmad khader commentedTys, @marcus.
Tested the guardrailis working as expected, small bug is the
tokenizer_modelvisibility, which is not working correctly, should be':input[name="guardrail_settings[use_tokens]"]' => ['checked' => TRUE],instead of':input[name="use_tokens"]' => ['checked' => TRUE],.Since it's a small bug, I'll fix it and move to RTBC.
Comment #8
ahmad khader commentedComment #9
marcus_johansson commentedI will split this up into one bug issue for the schema missing in Guardrails in general, so it can be backported.
Will assume that its RTBC'd on both, but setting back to Needs Work, so no one merges it by mistake.
Comment #10
ahmad khader commentedCreated #3583785: Fix: Guardrail and Guardrail Set config entities have incomplete config schema for backporting the bug fix.
Comment #11
marcus_johansson commentedSetting RTBC again and then merge.
Comment #12
marcus_johansson commented