LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-coreutilsformattingStrictFormatter
    Class●Since v0.1

    StrictFormatter

    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.

    Copy
    StrictFormatter()

    Bases

    Formatter

    Example:

    fmt = StrictFormatter() fmt.format("Hello, {name}!", name="World") 'Hello, World!' fmt.format("Hello, {}!", "World") # Raises ValueError

    Methods

    method
    vformat

    Format a string using only keyword arguments.

    Overrides the base vformat to reject positional arguments, ensuring all substitutions are explicit and named.

    method
    validate_input_variables

    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.

    View source on GitHub