> This page is for Server SDKs.

> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# expected_answer

> Build the expected answer length dict for a gather question.

[ref-set-expected-answer]: /docs/server-sdks/reference/python/agents/context-builder/step/set-expected-answer

[ref-add-gather-question]: /docs/server-sdks/reference/python/agents/context-builder/step/add-gather-question

Build an `expected_answer` dict for a gather question's `expected_answer`
argument in [`add_gather_question()`][ref-add-gather-question]. It takes the
same arguments, and applies the same checks, as
[`Step.set_expected_answer()`][ref-set-expected-answer].

```python
from signalwire.core.contexts import expected_answer
```

## Parameters

**`digits`** `int | None` — default: None

The exact number of digits, from 1 to 64. Can't be combined with
`min_digits` or `max_digits`.

---

**`min_digits`** `int | None` — default: None

Keyword-only. The fewest digits, from 1 to 64. Requires `max_digits`.

---

**`max_digits`** `int | None` — default: None

Keyword-only. The most digits, from 1 to 64, and at least `min_digits`.
Requires `min_digits`.

---

## Returns

`dict[str, int]` -- `{"digits": N}` or `{"min_digits": a, "max_digits": b}`.

## Raises

`ValueError` for a count outside 1 to 64, a `min_digits` greater than
`max_digits`, `digits` combined with a range, or a range with only one end.

## Example

```python
from signalwire.core.contexts import expected_answer

print(expected_answer(5))                            # {'digits': 5}
print(expected_answer(min_digits=4, max_digits=6))   # {'min_digits': 4, 'max_digits': 6}
```