Build secure and controlled AI Agents with Guardrails
Ensure data privacy safety by masking sensitive information and enforcing strict response rules.
This quickstart shows you how to use guardrails to automatically detect and protect PII (Personally Identifiable Information) while enforcing business rules with custom patterns, keeping your integrations secure and compliant.
What are guardrails?
Guardrails act as security layers between the user and the LLM. In Digibee, they:
Detect and mask sensitive data: Identify and mask personal identifiers (CPF, CNPJ), financial data (credit cards, IBAN), contact details (email, phone numbers), technical identifiers (IP addresses, URLs), crypto wallet addresses, and other configurable patterns.
Validate input patterns: Block specific data formats before processing the request to ensure the AI follows a predefined pattern.
Prerequisites
Before you begin, make sure you have:
An API key from an LLM provider (for example, OpenAI, Anthropic, or Google).
The API key registered in Digibee as a Secret Key account. For details, see how to create a Secret Key account.
Initial setup
Add the Agent Component to your pipeline immediately after the trigger and configure it as follows:
Model: Select your preferred model (for example, OpenAI – GPT-4o Mini).
Account: Click the gear icon next to the Model parameter, go to Account, and select the Secret Key account you created in Digibee.
Once the basic configuration is complete, you are ready to configure your guardrails.
Scenario
You are building an Agent to process refund requests. It must identify whether the request is valid, never send sensitive customer data to the AI provider, and ensure that the output format is readable by a database.
To ensure data privacy and compliance, configure the Agent with the following messages:
System Message
User Message
Step-by-step
1. Enable PII detection (Masking) and JSON Schema validation
Protect your customers' privacy by ensuring sensitive data is never sent in plain text to the LLM provider .
Open the Agent Component and click the gear icon (⚙️) next to Guardrails.
In the settings, enable Mask on detection.
Select the specific patterns you want to protect. For this example, select:
CPF detection (Brazilian national identifier for individuals)
Email detection
After selecting the patterns, enable JSON Schema to validate the model’s response against the defined structure. If the response does not match the schema, the Agent automatically requests a correction; if validation still fails, the execution ends with an error.
2. Add Custom Regex validation
Add a custom pattern to ensure that the Agent only processes legitimate internal order codes:
On the same Guardrails page, enable Regex.
Configure:
Pattern Name:
Valid_Order_CodeRegex Pattern:
REF-\d{4}
Click Save.
3. Ensure structured output (JSON Schema)
Guardrails also monitor the model's output. The JSON Schema option was enabled in Step 1. To enforce a machine-readable response, you will define the schema itself in the next steps. Once both configurations are in place, the Agent validates responses against this schema and automatically retries if the output doesn’t comply on the first attempt.
Click the gear icon (⚙️) next to Model and enable Use JSON Schema. .
Define the output schema into the JSON Schema definition field (ensure the
$schematag is present):
4. Test the Guardrails
Enter the following input in the Output Details section to see how the protection is applied, then click Run to execute the test.
Input:
Output (Final result):
How it works
To ensure security and consistency, the Agent Component follows this internal process:
Data redaction
Before the prompt is sent to the LLM (OpenAI, Google, or others), Digibee scans the text for sensitive data. If information such as a CPF, email address, or other identifiable data is detected, the Platform replaces it with a placeholder. This ensures the provider never receives the real data, helping you stay compliant with privacy laws.
Reprompt logic
When JSON Schema validation is enabled, the Agent validates the model’s response against the defined schema. If the response doesn’t match the expected structure (for example, a required field is missing), the Agent automatically sends a correction request to the model. If the response still fails validation, the execution ends with an error.
Result
Kudos! You've built a secure, production-ready AI Agent with masked data, enforced business rules via Regex, and outputs guaranteed by JSON Schema validation.
Last updated
Was this helpful?