Guardrails for Embedding Requests
Apply security and data validation measures to vector embedding requests to protect sensitive information and ensure data quality.
Portkey’s guardrails aren’t limited to chat completions - they can also be applied to embedding requests. This means you can protect your embedding workflows with the same robust security measures you use for your other LLM interactions.
Why Use Guardrails for Embeddings?
Vector embeddings form the backbone of modern AI applications, transforming text into numerical representations that power semantic search, recommendation systems, and RAG pipelines. However, unprotected embedding workflows create significant business risks that technical leaders cannot ignore.
Without proper guardrails, sensitive customer data can leak into vector databases, toxic content can contaminate downstream systems, and resources are wasted embedding low-quality inputs. Protecting these workflows is essential because:
- Data leakage prevention: Stop PII, PHI, or sensitive information from being sent to embedding models
- Data quality control: Ensure only clean, formatted data gets embedded
- Cost optimization: Avoid unnecessary API calls for data that doesn’t meet your criteria
- Compliance: Maintain regulatory compliance by filtering problematic content
By implementing guardrails at the embedding stage, you create a critical safety layer that protects your entire AI pipeline. For technical teams already building with embeddings, Portkey’s guardrails integrate seamlessly with existing workflows while providing the security measures that enterprise applications demand.
How It Works
Guardrails for embeddings are applied at the “before request” stage, examining your text before it’s sent to the embedding model:
- Your application sends text to Portkey for embedding
- Portkey’s guardrails analyze the text before sending to the LLM provider
- If the text passes all checks, it’s sent to the embedding model
- If it fails, the configured guardrail action is taken (deny, feedback, etc.)
Supported Guardrails for Embeddings
You can use any of Portkey’s “before request” guardrails with embedding requests:
PII Detection
Protect user privacy by preventing PII from being embedded
Regex Match
Filter content based on custom pattern matching
Contains Check
Block embedding requests with specific words/phrases
Word/Character Count
Ensure embeddings meet appropriate length requirements
Contains Code
Detect and block code snippets from being embedded
Custom Webhook
Implement your own custom guardrail logic
Partner Guardrails
Utilize guardrails from Pangea, Pillar, and other partners
PHI Detection
Prevent healthcare data from entering embedding systems
Moderate Content
Filter out harmful content before embedding
Setting Up Embedding Guardrails
1. Create a Guardrail
Follow the standard process to create a guardrail in Portkey:
- Navigate to the
Guardrails
page and clickCreate
- Select the appropriate check from available guardrails (e.g., PII Detection, Regex Match)
- Configure the check parameters & set desired actions for failed checks
- Save the guardrail to get its ID
Make sure to select guardrails that support the beforeRequestHook
since embeddings only use pre-request validation.
2. Add the Guardrail to Your Config
Add your guardrail ID to the before_request_hooks
in your Portkey config:
3. Use the Config with Embedding Requests
Common Use Cases
-
Protecting Against PII in Embeddings: When building search systems or RAG applications, you need to ensure no personally identifiable information is inadvertently embedded:
-
Filtering Code from Document Embeddings: If you’re building a knowledge base that shouldn’t include code snippets:
-
Size-Based Filtering: Ensure only appropriately sized documents get embedded:
-
Custom Regex Filtering: Create domain-specific filters using regex patterns:
Monitoring and Logs
All guardrail actions on embedding requests are logged in the Portkey dashboard, just like other guardrail activities. You can:
- See which embedding requests were blocked
- View detected issues (PII, regex matches, etc.)
- Track guardrail performance over time
- Export logs for compliance reporting
Get Support
If you’re implementing guardrails for embeddings and need assistance, reach out to the Portkey team on the community forum.
Learn More
Was this page helpful?