Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented guardrail service with APIs to effectively manage guardrails in the system #160 #165

Open
wants to merge 87 commits into
base: main
Choose a base branch
from

Conversation

vinayakbagal7
Copy link

@vinayakbagal7 vinayakbagal7 commented Dec 20, 2024

Change Description

Implemented guardrail service with APIs to effectively manage guardrails in the system

  1. Added APIs to handle all CRUD operations for guardrail connections.

Example payload -

{
   "name": "gr_connection_1",
   "description": "test description",
   "guardrailsProvider": "AWS",
   "connectionDetails": {
       "access_key": "<aws_access_key>",
       "secret_key": "<aws_secret_ky>",
       "session_token": "<aws_session_token>"
   },
   "encryptFields": ["secret_key", "session_token"]
}
  1. API to test connections to external services with the same payload as above.
  2. APIs to handle all CRUD operations for guardrails.
  3. Handled different types of configurations below in the guardrail.
  1. Content Moderation
  2. Off Topics filters
  3. Denied Terms
  4. Sensitive Data Filtering
  5. Prompt Safety

Example payload for guardrail -

{
   "name": "test_gr_1",
   "description": "test guardrail 1",
   "version": 1,
   "applicationKeys": [
       "632bc4a449580d9766f5845179bb8b6e",
       "6b2d2f21acdac859d3fb3804484b99a7",
       "5c4c5df2daca1210f34120af6c689187"
   ],
   "guardrailConnectionName": "gr_connection_1",
   "guardrailProvider": "AWS",
   "guardrailConfigs": [
       {
           "configType": "CONTENT_MODERATION",
           "responseMessage": "I couldn't respond to that message.",
           "configData": {
               "configs": [
                   {
                       "category": "Hate",
                       "filterStrengthPrompt": "high",
                       "filterStrengthResponse": "medium"
                   },
                   {
                       "category": "Insults",
                       "filterStrengthPrompt": "high",
                       "filterStrengthResponse": "medium"
                   }
               ]
           }
       },
       {
           "configType": "SENSITIVE_DATA",
           "responseMessage": "I couldn't respond to that message.",
           "configData": {
               "configs": [
                   {
                       "category": "EMAIL",
                       "action": "DENY"
                   },
                   {
                       "category": "USERNAME",
                       "action": "ALLOW"
                   },
                   {
                       "category": "PASSWORD",
                       "action": "REDACT"
                   },
                   {
                       "type": "regex",
                       "name": "email_regex",
                       "description": "email_regex",
                       "pattern": "test_pattern",
                       "action": "REDACT"
                   }
               ]
           }
       },
       {
           "configType": "OFF_TOPIC",
           "responseMessage": "I couldn't respond to that message.",
           "configData": {
               "configs": [
                   {
                       "topic": "Sports",
                       "definition": "Sports Definition",
                       "samplePhrases": [
                           "Who's playing NFL tonight ?",
                           "Who's leading tonight ?"
                       ],
                       "action": "DENY"
                   }
               ]
           }
       },
       {
           "configType": "DENIED_TERMS",
           "responseMessage": "I couldn't respond to that message.",
           "configData": {
               "configs": [
                   {
                       "type": "PROFANITY",
                       "value": true
                   },
                   {
                       "term": "Violance",
                       "keywords": [
                           "Violent Bahaviour",
                           "Physical Assault"
                       ]
                   }
               ]
           }
       },
       {
           "configType": "PROMPT_SAFETY",
           "responseMessage": "I couldn't respond to that message.",
           "configData": {
               "configs": [
                   {
                       "category": "PROMPT_ATTACK",
                       "filterStrengthPrompt": "HIGH"
                   }
               ]
           }
       }
   ]
}
  1. CRUD API to manage response message templates.

  2. "Get Guardrail" API specifically for the shield service based on lastKnownVersion.
    Example response -

{
   "applicationKey": "632bc4a449580d9766f5845179bb8b6e",
   "version": 3,
   "guardrails": [
       {
           "id": 1,
           "status": 1,
           "createTime": "2024-12-20T08:46:36.899617",
           "updateTime": "2024-12-20T08:52:36.900342",
           "name": "test_gr_1",
           "description": "test guardrail 1",
           "version": 6,
           "guardrailProvider": "AWS",
           "guardrailConnectionName": "gr_connection_1",
           "guardrailConfigs": [
               {
                   ...
               }
           ],
           "guardrailProviderResponse": {
               "success": true,
               "response": {
                   "guardrailId": "j0vwca4b8swg",
                   "guardrailArn": "arn:aws:bedrock:us-east-1:404161567776:guardrail/j0vwca4b8swg",
                   "version": "DRAFT"
               }
           },
           "guardrailConnectionDetails": {
               "access_key": "<aws_secret_key>",
               "secret_key": "<aws_secret_key_encrypted>",
               "session_token": "<aws_session_token_encrypted>",
               "encryption_key_id": <id>
           }
       }
   ]
}

Issue reference

This PR fixes issue #160

Checklist

  • I have reviewed the contribution guidelines
  • My code includes unit tests
  • All unit tests and lint checks pass locally
  • My PR contains documentation updates/additions if required

vinayakbagal and others added 30 commits December 5, 2024 11:35
@andbenn andbenn added the enhancement New feature or request label Jan 13, 2025
Copy link
Collaborator

@akshayr-privacera-github akshayr-privacera-github left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets do the required changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants