# encode_multi_select_answer

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/_ask_user_types/encode_multi_select_answer)

Encode the selected values of a `multi_select` answer for the wire.

The answer stays one string so `answers: list[str]` keeps one slot per
question, positionally matched. JSON is self-delimiting, so values carrying
commas, quotes, or newlines round-trip exactly.

The encoding is opaque to a consumer that only moves the answer around. A
consumer that tests whether the user answered at all must go through
`ask_user_answer_is_empty`: an unselected `multi_select` encodes as the
*truthy* string `[]`, so a bare `.strip()` reads it as answered.

## Signature

```python
encode_multi_select_answer(
    values: list[str],
) -> str
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `values` | `list[str]` | Yes | Selected values — toggled predefined choices in choice-list order, then custom Other values in slot order. |

## Returns

`str`

The values as a JSON array, e.g. `["a", "b"]`. An empty selection

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/2069079e09546060f5b52b2cd4f0e3c813e820f3/libs/code/deepagents_code/_ask_user_types.py#L66)