langchain-ai/langgraph · error · ValueError

Unrecognized . Expected one of 'langchain-openai', None.

Error message

Unrecognized {format=}. Expected one of 'langchain-openai', None.

What it means

Raised in message merging (add_messages / RemoveMessage handling) when the format argument is neither None, 'langchain-openai', nor falsy. It is an input-validation guard on the format parameter: an unsupported serialization format name was passed to a message-merging helper. Use 'langchain-openai' or omit the argument.

Solutions

  1. Pass format=None to keep native message objects
  2. Pass format='langchain-openai' to convert to OpenAI-style dicts
  3. Implement custom formatting after the merge instead of an unsupported format string
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at libs/langgraph/langgraph/graph/message.py:240 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of langchain-ai/langgraph@38031739e5 (2026-08-26). Data as JSON: /api/errors/7e38f1757924c0d4. Report an issue: GitHub.

Appendix: source

Thrown at libs/langgraph/langgraph/graph/message.py:240

                ids_to_remove.add(m.id)
            else:
                ids_to_remove.discard(m.id)
                merged[existing_idx] = m
        else:
            if isinstance(m, RemoveMessage):
                raise ValueError(
                    f"Attempting to delete a message with an ID that doesn't exist ('{m.id}')"
                )

            merged_by_id[m.id] = len(merged)
            merged.append(m)
    merged = [m for m in merged if m.id not in ids_to_remove]

    if format == "langchain-openai":
        merged = _format_messages(merged)
    elif format:
        msg = f"Unrecognized {format=}. Expected one of 'langchain-openai', None."
        raise ValueError(msg)
    else:
        pass

    return merged


def _messages_delta_reducer(
    state: list[AnyMessage], writes: list[list[AnyMessage]]
) -> list[AnyMessage]:
    """**Experimental.** Batch reducer for use with `DeltaChannel`.

    Processes all writes in one pass — dedup by ID, `RemoveMessage`
    tombstoning — without calling `add_messages`.

    This reducer is batching-invariant, as required by `DeltaChannel`:
    `reducer(reducer(state, xs), ys) == reducer(state, xs + ys)`.

    Raw dict / string / tuple inputs are coerced to typed `BaseMessage`

View on GitHub (pinned to 38031739e5)