Toggle Menu
Prev Up Next

# Source code for langchain_core.utils.formatting

    """Utilities for formatting strings."""
    from string import Formatter
    from typing import Any, List, Mapping, Sequence

    class StrictFormatter(Formatter):
        """Formatter that checks for extra keys."""

        def vformat(
            self, format_string: str, args: Sequence, kwargs: Mapping[str, Any]
        ) -> str:
            """Check that no arguments are provided."""
            if len(args) > 0:
                raise ValueError(
                    "No arguments should be provided, "
                    "everything should be passed as keyword arguments."
                )
            return super().vformat(format_string, args, kwargs)

        def validate_input_variables(
            self, format_string: str, input_variables: List[str]
        ) -> None:
            dummy_inputs = {input_variable: "foo" for input_variable in input_variables}
            super().format(format_string, **dummy_inputs)

    formatter = StrictFormatter()