Home / Function/ validate_input_variables() — langchain Function Reference

validate_input_variables() — langchain Function Reference

Architecture documentation for the validate_input_variables() function in formatting.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  4ce9db10_cabc_c1fc_0a4d_5ab4e48fffee["validate_input_variables()"]
  29112ca2_d607_429e_5319_09bd1ea18686["StrictFormatter"]
  4ce9db10_cabc_c1fc_0a4d_5ab4e48fffee -->|defined in| 29112ca2_d607_429e_5319_09bd1ea18686
  style 4ce9db10_cabc_c1fc_0a4d_5ab4e48fffee fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/utils/formatting.py lines 50–75

    def validate_input_variables(
        self, format_string: str, input_variables: list[str]
    ) -> None:
        """Validate that input variables match the placeholders in a format string.

        Checks that the provided input variables can be used to format the given string
        without missing or extra keys. This is useful for validating prompt templates
        before runtime.

        Args:
            format_string: A string containing replacement fields to validate
                against (e.g., `'Hello, {name}!'`).
            input_variables: List of variable names expected to fill the
                replacement fields.

        Raises:
            KeyError: If the format string contains placeholders not present
                in input_variables.

        Example:
            >>> fmt = StrictFormatter()
            >>> fmt.validate_input_variables("Hello, {name}!", ["name"])  # OK
            >>> fmt.validate_input_variables("Hello, {name}!", ["other"])  # Raises
        """
        dummy_inputs = dict.fromkeys(input_variables, "foo")
        super().format(format_string, **dummy_inputs)

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free