Home / Function/ _handle_validation_error() — langchain Function Reference

_handle_validation_error() — langchain Function Reference

Architecture documentation for the _handle_validation_error() function in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  7cfccf7f_59e7_df70_47a7_ac13e2b6d05d["_handle_validation_error()"]
  80cebff4_efbd_4311_85e9_de0dc81a7eee["base.py"]
  7cfccf7f_59e7_df70_47a7_ac13e2b6d05d -->|defined in| 80cebff4_efbd_4311_85e9_de0dc81a7eee
  51b059af_20e0_9233_077d_cd590dd94dc8["run()"]
  51b059af_20e0_9233_077d_cd590dd94dc8 -->|calls| 7cfccf7f_59e7_df70_47a7_ac13e2b6d05d
  c2f33b98_e5b2_c424_d7d3_8cbd05da78d1["arun()"]
  c2f33b98_e5b2_c424_d7d3_8cbd05da78d1 -->|calls| 7cfccf7f_59e7_df70_47a7_ac13e2b6d05d
  style 7cfccf7f_59e7_df70_47a7_ac13e2b6d05d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/tools/base.py lines 1149–1178

def _handle_validation_error(
    e: ValidationError | ValidationErrorV1,
    *,
    flag: Literal[True] | str | Callable[[ValidationError | ValidationErrorV1], str],
) -> str:
    """Handle validation errors based on the configured flag.

    Args:
        e: The validation error that occurred.
        flag: How to handle the error (`bool`, `str`, or `Callable`).

    Returns:
        The error message to return.

    Raises:
        ValueError: If the flag type is unexpected.
    """
    if isinstance(flag, bool):
        content = "Tool input validation error"
    elif isinstance(flag, str):
        content = flag
    elif callable(flag):
        content = flag(e)
    else:
        msg = (
            f"Got unexpected type of `handle_validation_error`. Expected bool, "
            f"str or callable. Received: {flag}"
        )
        raise ValueError(msg)  # noqa: TRY004
    return content

Subdomains

Called By

Frequently Asked Questions

What does _handle_validation_error() do?
_handle_validation_error() is a function in the langchain codebase, defined in libs/core/langchain_core/tools/base.py.
Where is _handle_validation_error() defined?
_handle_validation_error() is defined in libs/core/langchain_core/tools/base.py at line 1149.
What calls _handle_validation_error()?
_handle_validation_error() is called by 2 function(s): arun, run.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free