# ScopeGuard-2 on the hosted API

Source: https://orbitals.principled.app/docs/hosted-api/scope-guard-v2/overview/

**ScopeGuard-2** checks whether a user message is in scope for your AI service before your LLM answers it. On the hosted API it runs on our servers: you send the conversation and your AI service description, and get back one of seven [scope classes](https://orbitals.principled.app/docs/guide/orbitals/scope-guard-v2/#scope-classes), with nothing to download or serve.

The hosted API serves one model, `scope-guard-v2-pro-2609`, the Pro version of ScopeGuard-2, not published on Hugging Face. It is the default when you leave out `model`.

[See it in the Playground: Example conversations, each with what ScopeGuard-2 returned.](https://orbitals.principled.app/docs/playground/?orbital=scope-guard-v2)

## Quickstart

With your [API key](https://orbitals.principled.app/docs/hosted-api/quickstart/#api-key), send the conversation so far, ending with the user's message:

**Python**

Setup

```bash
pip install orbitals  # Python 3.10 or later
export PRINCIPLED_API_KEY="principled_..."
```

first_call.py

```python
from orbitals.scope_guard_v2 import ScopeGuardV2

sg = ScopeGuardV2(
    backend="api",
    api_url="https://api.orbitals.principled.app",
)

result = sg.validate(
    [
        {
            "role": "user",
            "content": "I ordered a package, tracking number 1234567890",
        },
        {
            "role": "assistant",
            "content": (
                "Great, the package is in transit. "
                "What would you like to know?"
            ),
        },
        {
            "role": "user",
            "content": "If it does not arrive tomorrow, can I get a refund?",
        },
    ],
    ai_service_description=(
        "A virtual assistant for a parcel delivery service. "
        "It tracks packages by tracking number "
        "and gives expected delivery dates. "
        "It never handles refund requests."
    ),
)

print(result.scope_class.value)
```

Run it

```shell-session
$ python first_call.py
Restricted
```

**cURL**

Setup

```bash
export PRINCIPLED_API_KEY="principled_..."
```

```bash
curl -sS -X POST \
  "https://api.orbitals.principled.app/orbitals/scope-guard-v2/validate" \
  -H "X-API-Key: $PRINCIPLED_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  conversationstring | object | object[]requiredA bare string is one user message, a single object must have role "user" and a list must end with a user message.: [
    {
      "role": "user",
      "content": "I ordered a package, tracking number 1234567890"
    },
    {
      "role": "assistant",
      "content": "Great, the package is in transit. What would you like to know?"
    },
    {
      "role": "user",
      "content": "If it does not arrive tomorrow, can I get a refund?"
    }
  ],
  ai_service_descriptionstring | objectrequiredPlain text or a Structured V2 object; unknown keys are a 422. Which field drives which class: Scope classes.: "A virtual assistant for a parcel delivery service. It tracks packages by tracking number and gives expected delivery dates. It never handles refund requests."
}'
```

Your code branches on `scope_class`. Every other field and endpoint is in the [Reference](https://orbitals.principled.app/docs/hosted-api/scope-guard-v2/#validate).
