Guardrails
Guardrails are a set of configurable constraints that define how AI agents should respond to user messages. They ensure that responses adhere to specific policies, such as preventing offensive language, avoiding the disclosure of personally identifiable information (PII), maintaining a professional tone, and limiting responses to the intended scope.
Guardrails can be enabled or disabled via Agent Settings in the Studio or programmatically through code.
Configuring Guardrails in the Studio
To configure guardrails for an agent via the studio, follow these steps:
- Navigate to the Agent Studio tab in the left sidebar
- Select the agent you want to configure guardrails for
- Click on the Agent Settings tab
- Scroll to the Agent Guardrails section
- Enable or disable any of the four predefined guardrails as needed
- (Optional) Define a custom guardrail policy to specify additional constraints or guidelines
Configuring Guardrails in the Backend SDK
To programmatically update an agent's guardrails, use the Backend SDK's updateGuardrails
method. Below is an example complete with all four pre-set options for enabling guardrails:
await this.squid.ai().agent('AGENT_ID').updateGuardrails({ disableProfanity: true, professionalTone: true, disablePii: true, offTopicAnswers: true,});
To add a custom guardrail policy, use the updateCustomGuardrails
function:
await this.squid.ai().agent('AGENT_ID').updateCustomGuardrails('Sample custom guardrail');
To remove a custom guardrail policy, use the deleteCustomGuardrail
function:
await this.squid.ai().agent('AGENT_ID').deleteCustomGuardrail();
Configuring Guardrails via an API Request
To update an agent's guardrails using the API, send a POST request to the following endpoint:
POST /squid-api/v1/ai/agent/updateGuardrails
Below is an example payload request complete with all four pre-set options for enabling guardrails:
Content-Type: application/json{ "agentId": "your-agent-id", "guardrails": { "disablePii": true, "professionalTone": true, "offTopicAnswers": true, "disableProfanity": true }}
To update a custom guardrail using the API, send a POST request to the following endpoint:
POST /squid-api/v1/ai/agent/updateCustomGuardrails
Below is an example payload request for adding custom guardrails:
Content-Type: application/json{ "agentId": "your-agent-id", "customGuardrail": "'Sample custom guardrail'"}
To delete a custom guardrail using the API, send a POST request to the following endpoint:
POST /squid-api/v1/ai/agent/deleteCustomGuardrail
Below is an example payload request for deleting a custom guardrail:
Content-Type: application/json{ "agentId": "your-agent-id",}
Conclusion
Guardrails provide a robust mechanism for maintaining content quality, compliance, and professionalism in AI-generated responses. By configuring them via UI or code, users can tailor responses to their specific needs while ensuring responsible AI behavior.