{"record":{"id":"72dfcc2d7b837a76","repo":"OpenBB-finance/OpenBB","slug":"missing-argument-for-formatting-e","errorCode":null,"errorMessage":"Missing argument for formatting: {e}","messagePattern":"Missing argument for formatting: (.+?)","errorType":"exception","errorClass":"PromptError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/mcp_server/openbb_mcp_server/models/prompts.py","lineNumber":42,"sourceCode":"        # Validate required arguments\n        if self.arguments:\n            required = {arg.name for arg in self.arguments if arg.required}\n            provided = set(args)\n            missing = required - provided\n            if missing:\n                raise PromptError(f\"Missing required arguments: {missing}\")\n\n        try:\n            rendered_content = (\n                self.content.format(**args) if self.arguments or args else self.content\n            )\n            return [\n                PromptMessage(\n                    role=\"user\", content=TextContent(type=\"text\", text=rendered_content)\n                )\n            ]\n        except KeyError as e:\n            raise PromptError(f\"Missing argument for formatting: {e}\") from e\n","sourceCodeStart":24,"sourceCodeEnd":43,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/mcp_server/openbb_mcp_server/models/prompts.py#L24-L43","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Align the template and the argument declarations: every {placeholder} in content must exist in arguments (or argument_defaults)","Escape literal braces in templates by doubling them: {{not_a_placeholder}}","Supply the missing key explicitly: prompt.render(arguments={\"symbol\": \"AAPL\", ...})"],"exampleFix":"# before\n# content = \"Analyze {symbol}\"  but arguments declare \"ticker\"\n\n# after\n# content = \"Analyze {symbol}\" with arguments = [{\"name\": \"symbol\", \"required\": True}]","handlingStrategy":"validation","validationCode":"import string\n\ndeclared = {a.name for a in (prompt.arguments or {})} | set(prompt.argument_defaults or {})\nused = {\n    fn for _, fn, _, _ in string.Formatter().parse(prompt.content) if fn\n}\nundeclared = used - declared\nif undeclared:\n    raise ValueError(f\"template placeholders not declared as arguments: {undeclared}\")","typeGuard":"def template_is_bound(prompt) -> bool:\n    declared = {a.name for a in (prompt.arguments or [])} | set(\n        prompt.argument_defaults or {}\n    )\n    used = {\n        fn for _, fn, _, _ in string.Formatter().parse(prompt.content) if fn\n    }\n    return used <= declared","tryCatchPattern":"from openbb_mcp_server.models.prompts import PromptError\n\ntry:\n    messages = prompt.render(arguments=args)\nexcept PromptError as e:\n    if \"Missing argument for formatting\" in str(e):\n        key = str(e).rsplit(\"'\", 2)[-2]\n        args[key] = fallback_value_for(key)\n        messages = prompt.render(arguments=args)\n    else:\n        raise","preventionTips":["Run a template/arguments consistency check in prompt unit tests","Double literal braces ({{ }}) in templates that contain JSON or code snippets","Rename placeholders and declarations together in one commit to keep them in sync"],"tags":["mcp","prompts","formatting","keyerror"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}