Guardrails
Overview
Guardrails in LISA provide a powerful way to ensure safe and compliant model outputs through integration with AWS Bedrock Guardrails via LiteLLM. Guardrails can validate, filter, and control both input prompts and model responses, helping you enforce content policies, protect sensitive information, and maintain compliance standards.
Key Features
- AWS Bedrock Integration: Leverages AWS Bedrock Guardrails for robust content filtering
- Flexible Application Modes: Apply guardrails
pre-call,during-call, orpost-call - Group-Based Access Control: Target specific user groups with different guardrail policies
- Per-Model Configuration: Each model can have multiple guardrails with different settings
- Automatic Application: Guardrails are automatically applied based on user group membership
Architecture
Data Storage
Guardrails are stored in a dedicated DynamoDB table with the following structure:
- Partition Key:
guardrailId(LiteLLM-generated unique identifier) - Sort Key:
modelId(the model this guardrail is associated with) - Global Secondary Index:
ModelIdIndex(allows querying all guardrails for a specific model)
Guardrail Application Flow
- User Request: User sends a request to invoke a model
- Group Extraction: System extracts user's group memberships from JWT token
- Guardrail Lookup: System queries DynamoDB for guardrails associated with the model
- Group Matching: System determines which guardrails apply based on:
- Public guardrails (no
allowedGroupsspecified) apply to all users - Private guardrails apply only if user belongs to at least one
allowedGroups
- Public guardrails (no
- Guardrail Injection: Applicable guardrail are added to the LiteLLM request
- Validation: AWS Bedrock Guardrails validate the request/response
- Response Handling: If a guardrail is triggered, the admin configured guardrail response is returned
Prerequisites: Creating Guardrails in AWS Bedrock Console
Before you can attach guardrails to models in LISA, you must first create the guardrails in the AWS Bedrock Console.
Steps to Create a Guardrail in AWS Bedrock Console
Navigate to AWS Bedrock Console
- Open the AWS Console
- Navigate to Amazon Bedrock service
- Select "Guardrails" from the left navigation menu
Create a New Guardrail
- Click "Create guardrail"
- Provide a name for your guardrail
- Define blocked messaging responses
- Configure guardrail policies:
- Content filters: Filter harmful content categories (hate, insults, sexual, violence, etc.)
- Denied topics: Define topics to block
- Word filters: Block or redact specific words/phrases
- Sensitive information filters: Redact PII (email, phone, SSN, etc.)
- Contextual grounding: Prevent hallucinations and ensure relevance
Configure Guardrail Settings
- Configure version (
DRAFTor numbered version)
- Configure version (
Test Your Guardrail
- Use the AWS Console's test functionality
- Verify the guardrail behaves as expected
Note the Guardrail Details
- Copy the Guardrail ID (e.g.,
abc123xyz) - Note the Guardrail Version (e.g.,
DRAFT,1,2) - Alternatively, copy the full Guardrail ARN
- Copy the Guardrail ID (e.g.,
Guardrail Configuration
Configuration Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
guardrailName | string | Yes | Friendly name for the guardrail in LISA |
guardrailIdentifier | string | Yes | AWS Bedrock Guardrail ARN or ID |
guardrailVersion | string | No | Version to use (default: "DRAFT") |
mode | string | No | When to apply: "pre_call", "during_call", or "post_call" (default: "pre_call") |
description | string | No | Human-readable description of the guardrail's purpose |
allowedGroups | array | No | List of user groups this guardrail applies to (empty = public) |
Guardrail Modes
pre_call: Validates input prompts before sending to the modelduring_call: Validates during model processing (streaming scenarios)post_call: Validates model responses after generation
Managing Guardrails via LISA Models API
Creating a Model with Guardrails
Guardrails are attached to models as part of the model creation process. Include the guardrailsConfig field in your model creation request to apply a guardrail to a model:
POST /{deploymentStage}/models
{
"modelId": "my-model-id",
"modelName": "MyModel",
"streaming": true,
"features": [],
"modelType": "textgen",
"guardrailsConfig": {
"guardrail-1": {
"guardrailName": "ContentFilter",
"guardrailIdentifier": "abc123xyz",
"guardrailVersion": "1",
"mode": "pre_call",
"description": "Filters harmful content from user inputs",
"allowedGroups": ["team-a", "team-b"]
},
"guardrail-2": {
"guardrailName": "PIIProtection",
"guardrailIdentifier": "arn:aws:bedrock:us-east-1:123456789012:guardrail/xyz789",
"guardrailVersion": "DRAFT",
"mode": "post_call",
"description": "Redacts PII from model responses",
"allowedGroups": []
}
}
}Notes:
- The guardrail key (e.g., "guardrail-1") is an internal identifier
guardrailIdentifiermust match an existing AWS Bedrock Guardrail- Empty
allowedGroupsmeans the guardrail applies to all users - Multiple guardrails can be configured per model
- Guardrails are automatically registered in LiteLLM during model creation
Listing Guardrails
List All Guardrails via LiteLLM API
To view all guardrails registered in LiteLLM:
GET /v2/serve/v2/guardrails/listThis endpoint queries LiteLLM directly and returns all registered guardrails across all models.
Updating Guardrails
Update guardrails by sending a PUT request to update the model:
PUT /{deploymentStage}/models/{modelId}
{
"guardrailsConfig": {
"guardrail-1": {
"guardrailName": "ContentFilter",
"guardrailIdentifier": "abc123xyz",
"guardrailVersion": "2",
"mode": "pre_call",
"description": "Updated content filter with stricter rules",
"allowedGroups": ["team-a", "team-b", "team-c"]
}
}
}Update Operations:
- Modify Existing Guardrail: Include the guardrail with updated values
- Add New Guardrail: Include a new guardrail key with complete configuration
- Remove Guardrail: Set
markedForDeletion: trueon the guardrail
Deleting Guardrails
Guardrails are deleted when their associated model is deleted or when they are marked for deletion:
PUT /{deploymentStage}/models/{modelId}
{
"guardrailsConfig": {
"guardrail-1": {
"guardrailName": "ContentFilter",
"guardrailIdentifier": "abc123xyz",
"markedForDeletion": true
}
}
}This operation:
- Removes the guardrail from LiteLLM
- Deletes all associated guardrails from DynamoDB
- Removes guardrail configurations from LiteLLM
Note: Deleting a model does NOT delete the underlying AWS Bedrock Guardrail. It only removes the association between the guardrail and the LISA model and removes the guardrail from LiteLLM.
Managing Guardrails via UI
Creating Guardrails During Model Creation
- Create the Guardrail in AWS Bedrock Console first (see Prerequisites section)
- Navigate to Model Management and select Create Model
- Fill in the base model configuration
- Navigate to Guardrails Configuration
- Click Add Guardrail
- Configure the guardrail:
- Guardrail Name: Enter a friendly name
- Guardrail Identifier: Enter the AWS Bedrock Guardrail ARN or ID (from AWS Console)
- Guardrail Version: Specify version (default: DRAFT)
- Mode: Select when to apply (Pre Call, During Call, or Post Call)
- Description (optional): Describe the guardrail's purpose
- Allowed Groups (optional): Add group names that should have this guardrail
- Click Add to add groups, or press Enter after typing a group name
- Repeat steps 6-8 to add multiple guardrails
- Finish remaining configuration steps
- Click Create Model to finalize
Viewing Guardrails
- Navigate to Model Management
- Select a model card
- Select Actions and then Update
- Guardrails will be displayed in the model details under Guardrails Configuration
Updating / Removing Guardrails
- Navigate to Model Management
- Select the model card of the model you want to update
- Select Actions and then Update
- Navigate to Guardrails Configuration
- Modify existing guardrails
- Add new guardrails using the Add Guardrail button
- Remove guardrails by clicking the X button
- Navigate to final page and click Update Model to save changes
Note: When editing a model, clicking the X button marks guardrails for deletion rather than removing them immediately. They will be deleted when you save the model.
Best Practices
1. Design Guardrails in AWS Bedrock First
- Test guardrails thoroughly in AWS Bedrock Console before attaching to models
- Create separate guardrails for different purposes (content filtering, PII, compliance)
- Use descriptive names to identify guardrail purposes
2. Use Group-Based Access Appropriately
- Start with public guardrails for baseline protection
- Add team-specific guardrails for specialized requirements
- Document which groups require which guardrails
- Regularly audit group memberships
3. Monitor and Iterate
- Adjust guardrail sensitivity based on false positives/negatives
- Update guardrails in AWS Bedrock as policies and requirements evolve
- Update model configurations in LISA to use new guardrail versions
Troubleshooting
Guardrails Not Being Applied
Symptom: Requests are not being filtered as expected
Possible Causes:
- Guardrail doesn't exist in AWS Bedrock
- Guardrail identifier is incorrect
- Guardrail is not attached to model
- Guardrail version attached to model is incorrect
- User is not a member of the required groups
- AWS Bedrock Guardrail is not accessible from LISA VPC
Resolution:
- Verify guardrail exists in AWS Bedrock Console
- Check guardrail identifier configured in LISA matches AWS Bedrock Console
- Verify user group memberships
- Check guardrail configuration in model details
- Check CloudWatch logs for errors
- Check REST ECS Container for errors
Guardrail Updates Not Taking Effect
Symptom: Updated guardrail configuration not being applied
Possible Causes:
- Model update did not complete successfully
- Guardrail changes made in AWS Bedrock but version not updated in LISA
- Cache issues with model configuration
Resolution:
- Check model status (should be "In Service")
- Verify
guardrailVersionin LISA matches the version in AWS Bedrock - Check state machine execution logs
- Verify guardrail configuration
Invalid Guardrail Identifier Error
Symptom: Error during model creation or update mentioning invalid guardrail
Possible Causes:
- Guardrail doesn't exist in AWS Bedrock
- Incorrect guardrail ID or ARN
- Guardrail in different AWS region
Resolution:
- Verify guardrail exists in AWS Bedrock Console in the correct region
- Copy guardrail identifier directly from AWS Console
High Latency with Guardrails
Symptom: Requests take significantly longer with guardrails enabled
Possible Causes:
- Too many guardrails configured
- Complex guardrail rules in AWS Bedrock
Resolution:
- Reduce number of guardrails where possible
- Optimize guardrail rules in AWS Bedrock Console
- Consider using only critical guardrails for performance-sensitive applications
Additional Resources
- AWS Bedrock Guardrails Documentation
- LiteLLM Guardrails API
- LISA Model Management API Documentation