OpenBB-finance/OpenBB · error · PromptError

Missing argument for formatting: {e}

Error message

Missing argument for formatting: {e}

What it means

Thrown by Prompt.render when str.format on the prompt template raises KeyError — i.e. the template text references a placeholder like {symbol} that is not present in the merged argument dict. This is distinct from error 125: it catches placeholders the prompt template uses but that were never declared (or never supplied), including ones the required-arguments check did not cover.

Source

Thrown at openbb_platform/extensions/mcp_server/openbb_mcp_server/models/prompts.py:42

        # Validate required arguments
        if self.arguments:
            required = {arg.name for arg in self.arguments if arg.required}
            provided = set(args)
            missing = required - provided
            if missing:
                raise PromptError(f"Missing required arguments: {missing}")

        try:
            rendered_content = (
                self.content.format(**args) if self.arguments or args else self.content
            )
            return [
                PromptMessage(
                    role="user", content=TextContent(type="text", text=rendered_content)
                )
            ]
        except KeyError as e:
            raise PromptError(f"Missing argument for formatting: {e}") from e

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Align the template and the argument declarations: every {placeholder} in content must exist in arguments (or argument_defaults)
  2. Escape literal braces in templates by doubling them: {{not_a_placeholder}}
  3. Supply the missing key explicitly: prompt.render(arguments={"symbol": "AAPL", ...})

Example fix

# before
# content = "Analyze {symbol}"  but arguments declare "ticker"

# after
# content = "Analyze {symbol}" with arguments = [{"name": "symbol", "required": True}]
Defensive patterns

Strategy: validation

Validate before calling

import string

declared = {a.name for a in (prompt.arguments or {})} | set(prompt.argument_defaults or {})
used = {
    fn for _, fn, _, _ in string.Formatter().parse(prompt.content) if fn
}
undeclared = used - declared
if undeclared:
    raise ValueError(f"template placeholders not declared as arguments: {undeclared}")

Type guard

def template_is_bound(prompt) -> bool:
    declared = {a.name for a in (prompt.arguments or [])} | set(
        prompt.argument_defaults or {}
    )
    used = {
        fn for _, fn, _, _ in string.Formatter().parse(prompt.content) if fn
    }
    return used <= declared

Try / catch

from openbb_mcp_server.models.prompts import PromptError

try:
    messages = prompt.render(arguments=args)
except PromptError as e:
    if "Missing argument for formatting" in str(e):
        key = str(e).rsplit("'", 2)[-2]
        args[key] = fallback_value_for(key)
        messages = prompt.render(arguments=args)
    else:
        raise

Prevention

When it happens

Trigger: Prompt content is "Analyze {symbol}" but arguments only declare/bind "ticker", so format(**{"ticker": ...}) raises KeyError('symbol'). Also placeholders added to the template without updating the declared arguments list, or extra undeclared placeholders with no defaults.

Common situations: Editing prompt template text and forgetting to register the new placeholder as an argument, renaming a declared argument but not the template, a prompt authored with braces that were meant literally (e.g. JSON examples in the template) being interpreted as placeholders.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/72dfcc2d7b837a76. Report an issue: GitHub.