# ValidationNode

> **Class** in `langgraph.prebuilt`

📖 [View in docs](https://reference.langchain.com/python/langgraph.prebuilt/tool_validator/ValidationNode)

A node that validates all tools requests from the last `AIMessage`.

It can be used either in `StateGraph` with a `'messages'` key.

!!! note

    This node does not actually **run** the tools, it only validates the tool calls,
    which is useful for extraction and other use cases where you need to generate
    structured output that conforms to a complex schema without losing the original
    messages and tool IDs (for use in multi-turn conversations).

## Signature

```python
ValidationNode(
    self,
    schemas: Sequence[BaseTool | type[BaseModel] | Callable],
    *,
    format_error: Callable[[BaseException, ToolCall, type[BaseModel]], str] | None = None,
    name: str = 'validation',
    tags: list[str] | None = None,
)
```

## Description

**Example:**

```python title="Example usage for re-prompting the model to generate a valid response:"
from typing import Literal, Annotated
from typing_extensions import TypedDict

from langchain_anthropic import ChatAnthropic
from pydantic import BaseModel, field_validator

from langgraph.graph import END, START, StateGraph
from langgraph.prebuilt import ValidationNode
from langgraph.graph.message import add_messages

class SelectNumber(BaseModel):
    a: int

    @field_validator("a")
    def a_must_be_meaningful(cls, v):
        if v != 37:
            raise ValueError("Only 37 is allowed")
        return v

builder = StateGraph(Annotated[list, add_messages])
llm = ChatAnthropic(model="claude-3-5-haiku-latest").bind_tools([SelectNumber])
builder.add_node("model", llm)
builder.add_node("validation", ValidationNode([SelectNumber]))
builder.add_edge(START, "model")

def should_validate(state: list) -> Literal["validation", "__end__"]:
    if state[-1].tool_calls:
        return "validation"
    return END

builder.add_conditional_edges("model", should_validate)

def should_reprompt(state: list) -> Literal["model", "__end__"]:
    for msg in state[::-1]:
        # None of the tool calls were errors
        if msg.type == "ai":
            return END
        if msg.additional_kwargs.get("is_error"):
            return "model"
    return END

builder.add_conditional_edges("validation", should_reprompt)

graph = builder.compile()
res = graph.invoke(("user", "Select a number, any number"))
# Show the retry logic
for msg in res:
    msg.pretty_print()
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `schemas` | `Sequence[BaseTool \| type[BaseModel] \| Callable]` | Yes | A list of schemas to validate the tool calls with. These can be any of the following: - A pydantic BaseModel class - A BaseTool instance (the args_schema will be used) - A function (a schema will be created from the function signature) |
| `format_error` | `Callable[[BaseException, ToolCall, type[BaseModel]], str] \| None` | No | A function that takes an exception, a ToolCall, and a schema and returns a formatted error string. By default, it returns the exception repr and a message to respond after fixing validation errors. (default: `None`) |
| `name` | `str` | No | The name of the node. (default: `'validation'`) |
| `tags` | `list[str] \| None` | No | A list of tags to add to the node. (default: `None`) |

## Returns

`Union[Dict[str, List[ToolMessage]], Sequence[ToolMessage]]`

A list of
`ToolMessage` objects with the validated content or error messages.

## Extends

- `RunnableCallable`

## Constructors

```python
__init__(
    self,
    schemas: Sequence[BaseTool | type[BaseModel] | Callable],
    *,
    format_error: Callable[[BaseException, ToolCall, type[BaseModel]], str] | None = None,
    name: str = 'validation',
    tags: list[str] | None = None,
) -> None
```

| Name | Type |
|------|------|
| `schemas` | `Sequence[BaseTool \| type[BaseModel] \| Callable]` |
| `format_error` | `Callable[[BaseException, ToolCall, type[BaseModel]], str] \| None` |
| `name` | `str` |
| `tags` | `list[str] \| None` |


## Properties

- `schemas_by_name`

## ⚠️ Deprecated

ValidationNode is deprecated. Please use `create_agent` from `langchain.agents` with custom tool error handling.

---

[View source on GitHub](https://github.com/langchain-ai/langgraph/blob/aa322c13cd5f16a3f6254a931a4104e412cd687c/libs/prebuilt/langgraph/prebuilt/tool_validator.py#L43)