Home / Function/ build_extra_kwargs() — langchain Function Reference

build_extra_kwargs() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/core/langchain_core/utils/utils.py lines 262–310

def build_extra_kwargs(
    extra_kwargs: dict[str, Any],
    values: dict[str, Any],
    all_required_field_names: set[str],
) -> dict[str, Any]:
    """Build extra kwargs from values and extra_kwargs.

    !!! danger "DON'T USE"

        Kept for backwards-compatibility but should never have been public. Use the
        internal `_build_model_kwargs` function instead.

    Args:
        extra_kwargs: Extra kwargs passed in by user.
        values: Values passed in by user.
        all_required_field_names: All required field names for the pydantic class.

    Returns:
        Extra kwargs.

    Raises:
        ValueError: If a field is specified in both `values` and `extra_kwargs`.
        ValueError: If a field is specified in `model_kwargs`.
    """
    # DON'T USE! Kept for backwards-compatibility but should never have been public.
    for field_name in list(values):
        if field_name in extra_kwargs:
            msg = f"Found {field_name} supplied twice."
            raise ValueError(msg)
        if field_name not in all_required_field_names:
            warnings.warn(
                f"""WARNING! {field_name} is not default parameter.
                {field_name} was transferred to model_kwargs.
                Please confirm that {field_name} is what you intended.""",
                stacklevel=7,
            )
            extra_kwargs[field_name] = values.pop(field_name)

    # DON'T USE! Kept for backwards-compatibility but should never have been public.
    invalid_model_kwargs = all_required_field_names.intersection(extra_kwargs.keys())
    if invalid_model_kwargs:
        msg = (
            f"Parameters {invalid_model_kwargs} should be specified explicitly. "
            f"Instead they were passed in as part of `model_kwargs` parameter."
        )
        raise ValueError(msg)

    # DON'T USE! Kept for backwards-compatibility but should never have been public.
    return extra_kwargs

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free