Home / Function/ xor_args() — langchain Function Reference

xor_args() — langchain Function Reference

Architecture documentation for the xor_args() function in utils.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  eea73fc5_5eb7_2625_3f3e_7e62179f5c2f["xor_args()"]
  b77fd012_b825_e350_c8f5_a8f1b44997d9["utils.py"]
  eea73fc5_5eb7_2625_3f3e_7e62179f5c2f -->|defined in| b77fd012_b825_e350_c8f5_a8f1b44997d9
  style eea73fc5_5eb7_2625_3f3e_7e62179f5c2f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/utils/utils.py lines 24–55

def xor_args(*arg_groups: tuple[str, ...]) -> Callable:
    """Validate specified keyword args are mutually exclusive.

    Args:
        *arg_groups: Groups of mutually exclusive keyword args.

    Returns:
        Decorator that validates the specified keyword args are mutually exclusive.
    """

    def decorator(func: Callable) -> Callable:
        @functools.wraps(func)
        def wrapper(*args: Any, **kwargs: Any) -> Any:
            """Validate exactly one arg in each group is not None."""
            counts = [
                sum(1 for arg in arg_group if kwargs.get(arg) is not None)
                for arg_group in arg_groups
            ]
            invalid_groups = [i for i, count in enumerate(counts) if count != 1]
            if invalid_groups:
                invalid_group_names = [", ".join(arg_groups[i]) for i in invalid_groups]
                msg = (
                    "Exactly one argument in each of the following"
                    " groups must be defined:"
                    f" {', '.join(invalid_group_names)}"
                )
                raise ValueError(msg)
            return func(*args, **kwargs)

        return wrapper

    return decorator

Domain

Subdomains

Frequently Asked Questions

What does xor_args() do?
xor_args() is a function in the langchain codebase, defined in libs/core/langchain_core/utils/utils.py.
Where is xor_args() defined?
xor_args() is defined in libs/core/langchain_core/utils/utils.py at line 24.

Analyze Your Own Codebase

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

Try Supermodel Free