Repository navigation
[DEV-14680] Implement Guardrails for the Filter Search Endpoint - #4795
Open
gregrholden wants to merge 20 commits into
Open
gregrholden wants to merge 20 commits into
gregrholden wants to merge 20 commits into
Conversation
sethstoudenmier
previously approved these changes
Oct 6, 2026
…dingtransparency/usaspending-api into ftr/DEV-14680-guardrails
Contributor
Author
|
@sethstoudenmier @zachflanders-frb This is ready for another review. According to Ops, Guardrails is in place in NPC DEV so we can try testing it there before merging if desired. |
Contributor
|
I updated the view to return a search_error event if a guardrail is triggered in order to adhere to our api contract. I updated the api contract to make the search_id optional since this error is raised before the session is created so the search_id would be null. |
zachflanders-frb
approved these changes
Nov 10, 2026
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.
Description:
DEV-14680: Mechanism for running request through Guardrails
This branch includes a new services file (
guardrails.py) in thellmapplication. It provides a class that creates the requisite boto3 client to send queries to Bedrock Guardrails. A new response status code has been added to the filter-search endpoint to account for the added Guardrails behavior: Status 503 if Guardrails is unavailable or if the client is misconfigured in the app. With the async version of the endpoint in place, Guardrails error codes are now packaged in a JsonResponse with an integer value passed to a "status" attribute instead of as a DRF Response object. This should not be an issue, just an update in how it's packaged on the backend.The filter-search endpoint now also sends a Status 400 response if Guardrails intervenes and blocks the query.
This PR will require coordination with Ops and the Frontend team.
Technical Details:
IMPORTANT: If the Guardrails service is unavailable/unreachable, the Filter Search endpoint will cease functioning since it will block the query and return a 503 status code.
The
llm/v2/views/filter_search.pyendpoint was updated with a new function to handle passing queries to Bedrock Guardrails and returning its assessments. The endpoint can now send a 503 status if there is a misconfiguration in the app/client or if Guardrails is unavailable/unreachable. The endpoint will now send a 400 status if Guardrails intervenes.A new file at
llm/services/guardrails.pydefines theBedrockGuardrailServiceclass that:This change requires coordination with Ops to provision:
Environment variables in the ECS task definition (via terraform):
--
AWS_BEDROCK_GUARDRAIL_ID(can be either the Guardrail ID or the Guardrail ARN, either works)The ECS task definition will also need to include permissions to use the
bedrock:ApplyGuardrailAPI.Guardrail status codes are no longer wrapped in Response objects. They are packaged in JsonResponse objects with a custom "status" attribute containing an integer value of 400 or 503, depending on the error.
Frontend team needs to be made aware that the filter-search endpoint can now also distribute 503 status codes if Guardrails or the app are not configured to communicate.
Frontend team needs to also be made aware that should Guardrails intervene, they will receive a 400 status code.
The API contract has been updated with these changes.
Requirements for PR Merge:
Explain N/A in above checklist: