> For the complete documentation index, see [llms.txt](https://docs.mozilla.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mozilla.ai/api-reference/decide.md).

# Decide

Answer named yes/no, choice and score questions about a state

The `decide` and `adecide` functions answer named questions about a state (text, a JSON object, or an array) with a provider that supports the decide API. See [Decide](https://docs.mozilla.ai/decide.md) for the providers.

### `any_llm.decide()`

```
def decide(
    model: str,
    state: str | Mapping[str, Any] | Sequence[Any],
    questions: Mapping[str, Noul | Choice | Score | Mapping[str, Any]],
    *,
    provider: str | LLMProvider | None = None,
    api_key: str | None = None,
    api_base: str | None = None,
    client_args: dict[str, Any] | None = None,
    images: list[str] | None = None,
    **kwargs: Any,
) -> DecideResponse
```

### `any_llm.adecide()`

Async variant with the same parameters.

```
async def adecide(
    model: str,
    state: str | Mapping[str, Any] | Sequence[Any],
    questions: Mapping[str, Noul | Choice | Score | Mapping[str, Any]],
    *,
    provider: str | LLMProvider | None = None,
    api_key: str | None = None,
    api_base: str | None = None,
    client_args: dict[str, Any] | None = None,
    images: list[str] | None = None,
    **kwargs: Any,
) -> DecideResponse
```

### Parameters

| Parameter     | Type                                                         | Default    | Description                                                                                                                                       |
| ------------- | ------------------------------------------------------------ | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model`       | `str`                                                        | *required* | Provider-prefixed model ID (e.g., "typesafe:jev-latest").                                                                                         |
| `state`       | `str \| Mapping[str, Any] \| Sequence[Any]`                  | *required* | Text, a JSON object, or an array the questions refer to.                                                                                          |
| `questions`   | `Mapping[str, Noul \| Choice \| Score \| Mapping[str, Any]]` | *required* | Names mapped to `Noul`, `Choice` or `Score` questions, their dict forms, or objects with the same attributes.                                     |
| `provider`    | `str \| LLMProvider \| None`                                 | None       | Provider name or enum. Inferred from model string if omitted.                                                                                     |
| `api_key`     | `str \| None`                                                | None       | Provider API key. Falls back to environment variable.                                                                                             |
| `api_base`    | `str \| None`                                                | None       | Provider API base URL. Falls back to environment variable.                                                                                        |
| `client_args` | `dict[str, Any] \| None`                                     | None       | Additional arguments passed to the provider client constructor.                                                                                   |
| `images`      | `list[str] \| None`                                          | None       | Images the questions refer to, as data URLs (`data:image/...;base64,...`). Providers that do not accept images raise `UnsupportedParameterError`. |
| `**kwargs`    | `Any`                                                        | *required* | Additional arguments for the call, such as `timeout` in seconds.                                                                                  |

### Return Value

Returns a [`DecideResponse`](https://docs.mozilla.ai/api-reference/completion-1/decide.md) containing:

* `answers` -- one answer per question, keyed by question name.
* `nouls`, `choices`, `scores` -- the answers grouped by question type.
* `model` -- the model that served the request.
* `usage` -- token usage, when the provider reports it.
* `id` -- the provider's request ID, when it reports one.

### Usage

#### Every question type

```python
from any_llm import decide
from any_llm.types.decide import Choice, Noul, Score

result = decide(
    "typesafe:jev-latest",
    "I was charged twice. Please fix this ASAP.",
    {
        "billing": Noul(instructions="Is this ticket about billing?"),
        "tone": Choice(instructions="What is the tone?", criteria={"calm": None, "angry": None}),
        "urgency": Score(instructions="How urgent is this?", criteria=["low", "medium", "high"]),
    },
)

print(result.nouls["billing"].noul)
print(result.choices["tone"].choice)
print(result.scores["urgency"].score)
```

#### Async

```python
import asyncio
from any_llm import adecide
from any_llm.types.decide import Noul

async def main():
    result = await adecide(
        "typesafe:jev-latest",
        "I was charged twice.",
        {"billing": Noul(instructions="Is this ticket about billing?")},
    )
    print(result.nouls["billing"].noul)

asyncio.run(main())
```

{% hint style="info" %}
Not all providers support decide. Check the [providers page](https://docs.mozilla.ai/providers.md) for support details, or query `ProviderMetadata.decide` programmatically. A provider that does not support it raises `NotImplementedError`.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.mozilla.ai/api-reference/decide.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
