A string formatter that enforces keyword-only argument substitution.
This formatter extends Python's built-in string.Formatter to provide stricter
validation for prompt template formatting. It ensures that all variable
substitutions use keyword arguments rather than positional arguments, which improves
clarity and reduces errors when formatting prompt templates.
StrictFormatter()FormatterExample:
fmt = StrictFormatter() fmt.format("Hello, {name}!", name="World") 'Hello, World!' fmt.format("Hello, {}!", "World") # Raises ValueError
Format a string using only keyword arguments.
Overrides the base vformat to reject positional arguments, ensuring all
substitutions are explicit and named.
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.