> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portkey.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Guardrails for Embedding Requests

> Apply security and data validation measures to vector embedding requests to protect sensitive information and ensure data quality.

The Prisma AIRS AI Gateway'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:

1. **Data leakage prevention**: Stop PII, PHI, or sensitive information from being sent to embedding models
2. **Data quality control**: Ensure only clean, formatted data gets embedded
3. **Cost optimization**: Avoid unnecessary API calls for data that doesn't meet your criteria
4. **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, the AI Gateway'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:

```mermaid theme={"system"}
flowchart LR
    App[Your Application] --> Portkey[AI Gateway]
    Portkey --> Guardrails[Guardrail Checks]

    Guardrails -->|Pass| Success[/Success\nStatus: 240/]
    Guardrails -->|Fail + Deny=false| Warning[/Warning\nStatus: 446/]
    Guardrails -->|Fail + Deny=true| Blocked[/Blocked\nStatus: 446/]

    Success --> LLM[LLM Provider]
    Warning --> LLM

    class Success success
    class Warning warning
    class Blocked danger
```

1. Your application sends text to the AI Gateway for embedding
2. The AI Gateway's guardrails analyze the text before sending to the LLM provider
3. If the text passes all checks, it's sent to the embedding model
4. If it fails, the configured [guardrail action](/docs/aigw/product/guardrails) is taken (deny, feedback, etc.)

## Supported Guardrails for Embeddings

You can use any of the AI Gateway's "before request" guardrails with embedding requests:

<CardGroup cols={3}>
  <Card title="PII Detection" href="/docs/aigw/product/guardrails/pii-redaction">
    Protect user privacy by preventing PII from being embedded
  </Card>

  <Card title="Regex Match" href="/docs/aigw/product/guardrails/list-of-guardrail-checks#basic--deterministic-guardrails">
    Filter content based on custom pattern matching
  </Card>

  <Card title="Contains Check" href="/docs/aigw/product/guardrails/list-of-guardrail-checks#basic--deterministic-guardrails">
    Block embedding requests with specific words/phrases
  </Card>

  <Card title="Word/Character Count" href="/docs/aigw/product/guardrails/list-of-guardrail-checks#basic--deterministic-guardrails">
    Ensure embeddings meet appropriate length requirements
  </Card>

  <Card title="Contains Code" href="/docs/aigw/product/guardrails/list-of-guardrail-checks#basic--deterministic-guardrails">
    Detect and block code snippets from being embedded
  </Card>

  <Card title="Custom Webhook" href="/docs/product/guardrails/bring-your-own-guardrails">
    Implement your own custom guardrail logic
  </Card>

  <Card title="Partner Guardrails" href="/docs/aigw/product/guardrails/list-of-guardrail-checks#partner-guardrails">
    Utilize guardrails from Pangea, Pillar, and other partners
  </Card>

  <Card title="PHI Detection" href="/docs/aigw/product/guardrails/list-of-guardrail-checks#pro--llm-guardrails">
    Prevent healthcare data from entering embedding systems
  </Card>

  <Card title="Moderate Content" href="/docs/aigw/product/guardrails/list-of-guardrail-checks#pro--llm-guardrails">
    Filter out harmful content before embedding
  </Card>
</CardGroup>

[Learn More...](/docs/aigw/product/guardrails)

## Setting Up Embedding Guardrails

### 1. Create a Guardrail

Follow the standard process to create a guardrail in the AI Gateway:

* Navigate to the `Guardrails` page and click `Create`
* 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

<Note>
  Make sure to select guardrails that support the `beforeRequestHook` since embeddings only use pre-request validation.
</Note>

### 2. Add the Guardrail to Your Config

Add your guardrail ID to the `before_request_hooks` in your AI Gateway [config](/docs/aigw/product/ai-gateway/configs):

```json theme={"system"}
{
  "input_guardrails": ["gr-xxx", "gr-yyy", ...]
}
```

### 3. Use the Config with Embedding Requests

<Tabs>
  <Tab title="cURL">
    ```bash theme={"system"}
    curl https://aigw.portkey.ai/v1/embeddings \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $OPENAI_API_KEY" \
      -H "x-portkey-api-key: $PORTKEY_API_KEY" \
      -H "x-portkey-config: pc-xxx" \
      -d '{
        "model": "text-embedding-3-small",
        "input": "Your text string goes here"
      }'
    ```
  </Tab>
</Tabs>

## 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 Strata Cloud Manager, 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 [support@portkey.ai](mailto:support@portkey.ai).

## Learn More

* [AI Gateway Guardrails Overview](/docs/aigw/product/guardrails)
* [List of Guardrail Checks](/docs/aigw/product/guardrails/list-of-guardrail-checks)
* [Creating Raw Guardrails in JSON](/docs/aigw/product/guardrails/creating-raw-guardrails-in-json)


## Related topics

- [F5 Guardrails](/docs/aigw/integrations/guardrails/f5-guardrails.md)
- [Azure Guardrails](/docs/aigw/integrations/guardrails/azure-guardrails.md)
- [AWS Bedrock Guardrails](/docs/aigw/integrations/guardrails/bedrock-guardrails.md)
- [Request Parameters Check](/docs/aigw/integrations/guardrails/request-parameters-check.md)
- [Embeddings](/docs/aigw/integrations/llms/openai/embeddings.md)
