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

# Portkey

> Use Qualifire guardrails with Portkey to ensure your AI applications are safe, compliant, and high-quality

[Qualifire](https://qualifire.ai) offers a comprehensive suite of AI safety and quality guardrails that help ensure your AI applications are safe, compliant, and high-quality. The platform provides 20+ different guardrail checks covering content safety, AI quality, and compliance requirements.

<Steps>
  <Step title="Add Qualifire Credentials to Portkey">
    Add your Qualifire API key to Portkey:

    1. Click on the `Admin Settings` button on Sidebar
    2. Navigate to `Plugins` tab under Organisation Settings
    3. Click on the edit button for the Qualifire integration
    4. Add your Qualifire API Key - obtain this from your Qualifire account at [https://app.qualifire.ai/settings/api-keys/](https://app.qualifire.ai/settings/api-keys/)
  </Step>

  <Step title="Add Qualifire's Guardrail Checks">
    Create and configure guardrails:

    1. Navigate to the `Guardrails` page and click the `Create` button
    2. Search for any of the Qualifire guardrail checks and click `Add`
    3. Configure the specific parameters for your chosen guardrail
    4. Set any `actions` you want on your check, and create the Guardrail!

    <Note>
      Guardrail Actions allow you to orchestrate your guardrails logic. You can learn more about them in the [Portkey Guardrails documentation](https://docs.portkey.ai/product/guardrails#there-are-6-types-of-guardrail-actions).
    </Note>
  </Step>

  <Step title="Add Guardrail ID to Config">
    Add the Guardrail ID to your Portkey Config:

    1. When you save a Guardrail, you'll get an associated Guardrail ID
    2. Add this ID to the `input_guardrails` or `output_guardrails` params in your Portkey Config
    3. Create these Configs in Portkey UI, save them, and get an associated Config ID to attach to your requests

    ```json theme={null}
    {
      "input_guardrails": ["guardrails-id-xxx"],
      "output_guardrails": ["guardrails-id-yyy"]
    }
    ```
  </Step>

  <Step title="Make Your Request">
    Use your Config ID in your requests. Your requests are now protected by Qualifire's comprehensive guardrail system!

    <CodeGroup>
      ```javascript NodeJS theme={null}
      const portkey = new Portkey({
          apiKey: "PORTKEY_API_KEY",
          config: "pc-***" // Supports a string config id or a config object
      });
      ```

      ```python Python theme={null}
      portkey = Portkey(
          api_key="PORTKEY_API_KEY",
          config="pc-***" # Supports a string config id or a config object
      )
      ```

      ```javascript OpenAI NodeJS theme={null}
      const openai = new OpenAI({
        apiKey: 'OPENAI_API_KEY',
        baseURL: PORTKEY_GATEWAY_URL,
        defaultHeaders: createHeaders({
          apiKey: "PORTKEY_API_KEY",
          config: "CONFIG_ID"
        })
      });
      ```

      ```python OpenAI Python theme={null}
      client = OpenAI(
          api_key="OPENAI_API_KEY", # defaults to os.environ.get("OPENAI_API_KEY")
          base_url=PORTKEY_GATEWAY_URL,
          default_headers=createHeaders(
              provider="openai",
              api_key="PORTKEY_API_KEY", # defaults to os.environ.get("PORTKEY_API_KEY")
              config="CONFIG_ID"
          )
      )
      ```

      ```bash cURL theme={null}
      curl https://api.portkey.ai/v1/chat/completions \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer $OPENAI_API_KEY" \
        -H "x-portkey-api-key: $PORTKEY_API_KEY" \
        -H "x-portkey-config: $CONFIG_ID" \
        -d '{
          "model": "gpt-3.5-turbo",
          "messages": [{
              "role": "user",
              "content": "Hello!"
            }]
        }'
      ```
    </CodeGroup>

    <Note>
      For more details on Configs, refer to the [Portkey Config documentation](https://docs.portkey.ai/product/ai-gateway/configs).
    </Note>
  </Step>
</Steps>

## Available Guardrail Checks

Qualifire provides a comprehensive set of guardrail checks organized into five main categories:

<AccordionGroup>
  <Accordion title="Security" icon="shield-check">
    | Check Name              | Description                                                         | Parameters | Supported Hooks                         |
    | ----------------------- | ------------------------------------------------------------------- | ---------- | --------------------------------------- |
    | PII Check               | Checks that neither the user nor the model included PIIs            | None       | `beforeRequestHook`, `afterRequestHook` |
    | Prompt Injections Check | Checks that the prompt does not contain any injections to the model | None       | `beforeRequestHook`                     |
  </Accordion>

  <Accordion title="Safety" icon="shield-exclamation">
    | Check Name               | Description                                                                                                                           | Parameters | Supported Hooks                         |
    | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- | ---------- | --------------------------------------- |
    | Content Moderation Check | Checks for harmful content including sexual content, harassment, hate speech, and dangerous content in the user input or model output | None       | `beforeRequestHook`, `afterRequestHook` |
  </Accordion>

  <Accordion title="Reliability" icon="magnifying-glass">
    | Check Name                  | Description                                                                                  | Parameters                                                | Supported Hooks    |
    | --------------------------- | -------------------------------------------------------------------------------------------- | --------------------------------------------------------- | ------------------ |
    | Instruction Following Check | Checks that the model followed the instructions provided in the prompt                       | None                                                      | `afterRequestHook` |
    | Grounding Check             | Checks that the model is grounded in the context provided                                    | `mode` (optional) - [See Mode Parameter](#mode-parameter) | `afterRequestHook` |
    | Hallucinations Check        | Checks that the model did not hallucinate                                                    | `mode` (optional) - [See Mode Parameter](#mode-parameter) | `afterRequestHook` |
    | Tool Use Quality Check      | Checks the model's tool use quality. Including correct tool selection, parameters and values | `mode` (optional) - [See Mode Parameter](#mode-parameter) | `afterRequestHook` |
  </Accordion>

  <Accordion title="Policy" icon="gavel">
    | Check Name              | Description                                                           | Parameters                                                                                                                                                                                                                                       | Supported Hooks                         |
    | ----------------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------- |
    | Policy Violations Check | Checks that the prompt and response didn't violate any given policies | `policies` (array of strings) - [See Policy Violations Check](#policy-violations-check)<br />`mode` (optional) - [See Mode Parameter](#mode-parameter)<br />`policy_target` (optional) - [See Policy Violations Check](#policy-violations-check) | `beforeRequestHook`, `afterRequestHook` |
  </Accordion>
</AccordionGroup>

## Configuration Examples

### Mode Parameter

Several guardrail checks support a `mode` parameter that controls the trade-off between accuracy and speed:

* `quality`: Highest accuracy, slower processing
* `balanced`: Good balance between accuracy and speed (default)
* `speed`: Fastest processing, lower accuracy

```json theme={null}
{
  "mode": "quality"
}
```

### Policy Violations Check

For the Policy Violations Check, you can specify custom policies to enforce, the mode, and the target:

```json theme={null}
{
  "policies": [
    "The model cannot provide any discount to the user",
    "The model must not share internal company information",
    "The model must respond in a professional tone"
  ],
  "mode": "balanced",
  "policy_target": "both"
}
```

#### Parameters

* `policies` (required): Array of strings defining custom policies to enforce
* `mode` (optional): One of `quality`, `balanced`, or `speed`. Default: `balanced`
* `policy_target` (optional): One of `input`, `output`, or `both`. Specifies whether to run the policy check on the request, response, or both. This must match the configured hooks:
  * `input`: Only for `beforeRequestHook`
  * `output`: Only for `afterRequestHook`
  * `both`: For both `beforeRequestHook` and `afterRequestHook`

## Use Cases

<CardGroup cols={2}>
  <Card title="Content Moderation" icon="filter">
    Filter harmful or inappropriate content in user inputs and AI responses
  </Card>

  <Card title="Compliance" icon="clipboard-check">
    Ensure AI responses adhere to company policies and regulatory requirements
  </Card>

  <Card title="Quality Assurance" icon="chart-line">
    Detect hallucinations, instruction violations, and poor tool usage
  </Card>

  <Card title="Data Protection" icon="lock">
    Prevent PII exposure and ensure data privacy
  </Card>
</CardGroup>

## Observability

You can see the verdict and any actions taken directly in your Portkey logs! Monitor guardrail results to understand how your AI applications are performing and identify areas for improvement.

<Tip>
  Start with a `monitor` action on your guardrails to observe results before switching to `block` in production. This helps you tune thresholds without disrupting users.
</Tip>

## Get Support

If you face any issues with the Qualifire integration, join the [Portkey community forum](https://discord.gg/portkey-llms-in-prod-1143393887742861333) for assistance.

For Qualifire-specific support, visit the [Qualifire Documentation](/) or contact the Qualifire support team.

## Additional Resources

* [Qualifire Dashboard](https://app.qualifire.ai)
* [Portkey Documentation](https://docs.portkey.ai)
* [Portkey Guardrails Documentation](https://docs.portkey.ai/product/guardrails)
