# build_messages_input

> **Function** in `langchain_azure_ai`

📖 [View in docs](https://reference.langchain.com/python/langchain-azure-ai/agents/hosting/_converters/_request/build_messages_input)

Build a ``{"messages": [...]}`` LangGraph input from resolved items.

Prepends a ``SystemMessage`` when *instructions* is non-empty. Empty
item lists yield an empty messages list — callers should typically have
at least one user message before invoking the graph.

Incomplete tool-call sequences are filtered out: any ``AIMessage`` with
unanswered ``tool_calls`` and any orphan ``ToolMessage`` (whose
``tool_call_id`` has no matching preceding ``AIMessage.tool_calls``
entry) are dropped. This prevents poisoned conversation history —
e.g. one containing a ``function_call_output`` from a prior failed
request — from producing a message list the chat model would reject
("messages with role 'tool' must be a response to a preceding message
with 'tool_calls'").

## Signature

```python
build_messages_input(
    items: Sequence[Any],
    *,
    instructions: str | None = None,
    skip_call_ids: Iterable[str] = (),
) -> dict[str, list[AnyMessage]]
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `items` | `Sequence[Any]` | Yes | Resolved input items from the request. |
| `instructions` | `str \| None` | No | Optional system instructions from the request. (default: `None`) |
| `skip_call_ids` | `Iterable[str]` | No | Forwarded to :func:`items_to_messages`. Used by the HITL resume path to filter out the resume ``function_call_output``. (default: `()`) |

## Returns

`dict[str, list[AnyMessage]]`

The ``{"messages": [...]}`` payload accepted by ``MessagesState`` graphs.

---

[View source on GitHub](https://github.com/langchain-ai/langchain-azure/blob/7a6a664d617264df8dcb12fcfb1bacc09f21d504/libs/azure-ai/langchain_azure_ai/agents/hosting/_converters/_request.py#L186)