<!-- @nemo-nb: process -->
<!-- @nemo-nb: skip-test -->
<a id="guardrails-manage-configurations"></a>
# Manage Configurations

Guardrail configuration management operations (create, update, retrieve, list, delete) are available through `client.guardrail.configs`. Refer to [Configuration Structure](configuration-structure.md) for details on the configuration data schema.

---

## Setup

```python
import os
from nemo_platform import NeMoPlatform

client = NeMoPlatform(
    base_url=os.environ.get("NMP_BASE_URL", "http://localhost:8080"),
    workspace="default",
)
```

---

## Create a Configuration

Create a new guardrail configuration in the workspace.

```python
{% raw %}
config_data = {
    "prompts": [
        {
            "task": "self_check_input",
            "content": 'Your task is to check if the user message below complies with company policy.\n\nCompany policy:\n- should not contain harmful data\n- should not ask the bot to impersonate someone\n- should not contain explicit content\n\nUser message: "{{ user_input }}"\n\nQuestion: Should the user message be blocked (Yes or No)?\nAnswer:',
        },
        {
            "task": "self_check_output",
            "content": 'Your task is to check if the bot message below complies with company policy.\n\nCompany policy:\n- messages should not contain explicit content\n- messages should not contain harmful content\n- if refusing, should be polite\n\nBot message: "{{ bot_response }}"\n\nQuestion: Should the message be blocked (Yes or No)?\nAnswer:',
        },
    ],
    "instructions": [
        {
            "type": "general",
            "content": "Below is a conversation between a user and a helpful assistant bot.",
        }
    ],
    "rails": {
        "input": {"flows": ["self check input"]},
        "output": {"flows": ["self check output"]},
    },
}

config = client.guardrail.configs.create(
    name="my-guardrail-config",
    description="Self-check guardrail configuration",
    data=config_data,
)
{% endraw %}
```

??? "Example Output"
    :icon: code-square

    ```json
    {% raw %}
    {
      "id": "guardrail_config-4kSe8m3Nq7dGk2X7rY0h5L",
      "entity_id": "guardrail_config-4kSe8m3Nq7dGk2X7rY0h5L",
      "name": "my-guardrail-config",
      "workspace": "default",
      "project": null,
      "description": "Self-check guardrail configuration",
      "files_url": null,
      "data": {
        "prompts": [
          {
            "task": "self_check_input",
            "content": "Your task is to check if the user message below complies with company policy.\n\nCompany policy:\n- should not contain harmful data\n- should not ask the bot to impersonate someone\n- should not contain explicit content\n\nUser message: \"{{ user_input }}\"\n\nQuestion: Should the user message be blocked (Yes or No)?\nAnswer:"
          },
          {
            "task": "self_check_output",
            "content": "Your task is to check if the bot message below complies with company policy.\n\nCompany policy:\n- messages should not contain explicit content\n- messages should not contain harmful content\n- if refusing, should be polite\n\nBot message: \"{{ bot_response }}\"\n\nQuestion: Should the message be blocked (Yes or No)?\nAnswer:"
          }
        ],
        "instructions": [
          {
            "type": "general",
            "content": "Below is a conversation between a user and a helpful assistant bot."
          }
        ],
        "rails": {
          "input": {
            "flows": [
              "self check input"
            ]
          },
          "output": {
            "flows": [
              "self check output"
            ]
          }
        }
      },
      "created_at": "2026-01-20T03:00:00",
      "updated_at": "2026-01-20T03:00:00"
    }
    {% endraw %}
    ```

---

## List Configurations

List configurations in the workspace.

```python
configs = client.guardrail.configs.list()

print(f"Found {len(configs.data)} configurations:")
for c in configs.data:
    print(f"{c.name}: {c.description}")
```

Use the `filter` parameter to narrow results by `name`, `description`, `project`, `created_at`, or `updated_at`:

```python
# Filter by exact name
configs = client.guardrail.configs.list(filter={"name": "my-guardrail-config"})

# Filter by created_at range
configs = client.guardrail.configs.list(
    filter={"created_at": {"$gte": "2026-01-01T00:00:00"}}
)
```

??? "Example Output"
    :icon: code-square

    ```json
    {% raw %}
    {
      "data": [
        {
          "id": "guardrail_config-4kSe8m3Nq7dGk2X7rY0h5L",
          "entity_id": "guardrail_config-4kSe8m3Nq7dGk2X7rY0h5L",
          "name": "my-guardrail-config",
          "workspace": "default",
          "project": null,
          "description": "Self-check guardrail configuration",
          "files_url": null,
          "data": {
            "prompts": [
              {
                "task": "self_check_input",
                "content": "Your task is to check if the user message below complies with company policy.\n\nCompany policy:\n- should not contain harmful data\n- should not ask the bot to impersonate someone\n- should not contain explicit content\n\nUser message: \"{{ user_input }}\"\n\nQuestion: Should the user message be blocked (Yes or No)?\nAnswer:"
              },
              {
                "task": "self_check_output",
                "content": "Your task is to check if the bot message below complies with company policy.\n\nCompany policy:\n- messages should not contain explicit content\n- messages should not contain harmful content\n- if refusing, should be polite\n\nBot message: \"{{ bot_response }}\"\n\nQuestion: Should the message be blocked (Yes or No)?\nAnswer:"
              }
            ],
            "instructions": [
              {
                "type": "general",
                "content": "Below is a conversation between a user and a helpful assistant bot."
              }
            ],
            "rails": {
              "input": {
                "flows": [
                  "self check input"
                ]
              },
              "output": {
                "flows": [
                  "self check output"
                ]
              }
            }
          },
          "created_at": "2026-01-20T03:00:00",
          "updated_at": "2026-01-20T03:00:00"
        }
      ],
      "pagination": {
        "page": 1,
        "page_size": 10,
        "current_page_size": 1,
        "total_pages": 1,
        "total_results": 1
      },
      "sort": "created_at",
      "filter": null
    }
    {% endraw %}
    ```

---

## Get Configuration Details

Retrieve a specific configuration in the workspace by name.

```python
config = client.guardrail.configs.retrieve(
    name="my-guardrail-config",
)
```

??? "Example Output"
    :icon: code-square

    ```json
    {% raw %}
    {
      "id": "guardrail_config-4kSe8m3Nq7dGk2X7rY0h5L",
      "entity_id": "guardrail_config-4kSe8m3Nq7dGk2X7rY0h5L",
      "name": "my-guardrail-config",
      "workspace": "default",
      "project": null,
      "description": "Self-check guardrail configuration",
      "files_url": null,
      "data": {
        "prompts": [
          {
            "task": "self_check_input",
            "content": "Your task is to check if the user message below complies with company policy.\n\nCompany policy:\n- should not contain harmful data\n- should not ask the bot to impersonate someone\n- should not contain explicit content\n\nUser message: \"{{ user_input }}\"\n\nQuestion: Should the user message be blocked (Yes or No)?\nAnswer:"
          },
          {
            "task": "self_check_output",
            "content": "Your task is to check if the bot message below complies with company policy.\n\nCompany policy:\n- messages should not contain explicit content\n- messages should not contain harmful content\n- if refusing, should be polite\n\nBot message: \"{{ bot_response }}\"\n\nQuestion: Should the message be blocked (Yes or No)?\nAnswer:"
          }
        ],
        "instructions": [
          {
            "type": "general",
            "content": "Below is a conversation between a user and a helpful assistant bot."
          }
        ],
        "rails": {
          "input": {
            "flows": [
              "self check input"
            ]
          },
          "output": {
            "flows": [
              "self check output"
            ]
          }
        }
      },
      "created_at": "2026-01-20T03:00:00",
      "updated_at": "2026-01-20T03:00:00"
    }
    {% endraw %}
    ```

---

## Update a Configuration

Update one or more fields on an existing configuration.

```python
updated_config = client.guardrail.configs.update(
    name="my-guardrail-config",
    description="Updated guardrail configuration",
    data={
        "rails": {
            "output": {
                "streaming": {"enabled": True, "chunk_size": 300, "context_size": 100}
            }
        }
    },
)

print(f"Updated config: {updated_config.name}")
```

??? "Example Output"
    :icon: code-square

    ```json
    {% raw %}
    {
      "id": "guardrail_config-4kSe8m3Nq7dGk2X7rY0h5L",
      "entity_id": "guardrail_config-4kSe8m3Nq7dGk2X7rY0h5L",
      "name": "my-guardrail-config",
      "workspace": "default",
      "project": null,
      "description": "Updated guardrail configuration",
      "files_url": null,
      "data": {
        "prompts": [
          {
            "task": "self_check_input",
            "content": "Your task is to check if the user message below complies with company policy.\n\nCompany policy:\n- should not contain harmful data\n- should not ask the bot to impersonate someone\n- should not contain explicit content\n\nUser message: \"{{ user_input }}\"\n\nQuestion: Should the user message be blocked (Yes or No)?\nAnswer:"
          },
          {
            "task": "self_check_output",
            "content": "Your task is to check if the bot message below complies with company policy.\n\nCompany policy:\n- messages should not contain explicit content\n- messages should not contain harmful content\n- if refusing, should be polite\n\nBot message: \"{{ bot_response }}\"\n\nQuestion: Should the message be blocked (Yes or No)?\nAnswer:"
          }
        ],
        "instructions": [
          {
            "type": "general",
            "content": "Below is a conversation between a user and a helpful assistant bot."
          }
        ],
        "rails": {
          "input": {
            "flows": [
              "self check input"
            ]
          },
          "output": {
            "flows": [
              "self check output"
            ],
            "streaming": {
              "enabled": true,
              "chunk_size": 300,
              "context_size": 100
            }
          }
        }
      },
      "created_at": "2026-01-20T03:00:00",
      "updated_at": "2026-01-20T03:00:00"
    }
    {% endraw %}
    ```

---

## Delete a Configuration

Delete a configuration in the workspace by name.

```python
client.guardrail.configs.delete(
    name="my-guardrail-config",
)

print("Configuration deleted")
```

??? "Example Output"
    :icon: code-square

    ```json
    {
      "message": "Resource deleted successfully.",
      "id": "guardrail_config-4kSe8m3Nq7dGk2X7rY0h5L",
      "deleted_at": "2026-01-22T04:00:00Z"
    }
    ```
