fix: enforce guard max prompt length#820
Open
aishwaryagangaraj-web wants to merge 10 commits into
Open
Conversation
SdSarthak
requested changes
May 31, 2026
Owner
SdSarthak
left a comment
There was a problem hiding this comment.
The GuardPrompt type alias for prompt length enforcement is a clean approach. However this PR also removes the webhook trigger block that was intentionally added — the deliver_webhook call on guard_block decisions is a feature, not dead code. Please restore it before merging.
This PR also conflicts with recent merges to guard.py. After rebasing and restoring the webhook block, this is ready to merge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #763
This PR enforces
GUARD_MAX_PROMPT_LENGTHvalidation at the API request boundary for Guard scan endpoints.Previously,
/guard/scanaccepted arbitrarily large prompt payloads despite the configuredGUARD_MAX_PROMPT_LENGTHalready existing insettings. Validation only occurred later in the Guard pipeline, increasing unnecessary CPU and memory usage.This change rejects oversized prompts early at the request schema level and applies the same validation to batch scan requests.
Changes Made
GUARD_MAX_PROMPT_LENGTHonScanRequestmin_length=1andmax_length=settings.GUARD_MAX_PROMPT_LENGTHBulkScanRequest/guard/scan/batchfrom bypassing prompt length restrictionsType of Change
Checklist
pytest backend/tests/passes locally.envor any secretsTesting
Result:
test_guard_api.py