PrefectHQ/fastmcp · error · ValueError

Missing required arguments: {missing}

Error message

Missing required arguments: {missing}

What it means

A Prompt raises ValueError during render() because one or more arguments declared as required in the prompt's arguments spec were not supplied in the arguments dict. FastMCP validates required arguments up-front so the underlying render function never runs with an incomplete signature. The message lists the exact missing argument names in a set.

Source

Thrown at fastmcp_slim/fastmcp/prompts/function_prompt.py:324

                        ) from e
            else:
                # Parameter not in function signature, pass as-is
                converted_kwargs[param_name] = param_value

        return converted_kwargs

    async def render(
        self,
        arguments: dict[str, Any] | None = None,
    ) -> PromptResult:
        """Render the prompt with arguments."""
        # Validate required arguments
        if self.arguments:
            required = {arg.name for arg in self.arguments if arg.required}
            provided = set(arguments or {})
            missing = required - provided
            if missing:
                raise ValueError(f"Missing required arguments: {missing}")

        try:
            # Prepare arguments
            kwargs = arguments.copy() if arguments else {}

            # Convert string arguments to expected types BEFORE validation
            kwargs = self._convert_string_arguments(kwargs)

            # Filter out arguments that aren't in the function signature
            # This is important for security: dependencies should not be overridable
            # from external callers. self.fn is wrapped by without_injected_parameters,
            # so we only accept arguments that are in the wrapped function's signature.
            sig = inspect.signature(self.fn)
            valid_params = set(sig.parameters.keys())
            kwargs = {k: v for k, v in kwargs.items() if k in valid_params}

            # Use type adapter to validate arguments and handle Field() defaults
            # This matches the behavior of tools in function_tool

View on GitHub (pinned to 1f02114297)

Solutions

  1. Add the missing argument(s) named in the error to the arguments dict passed to render()
  2. If the argument should be optional, change its PromptArgument to required=False in the prompt's arguments spec
  3. If calling from a client, fetch the prompt's argument metadata (list_prompts / prompt.arguments) and construct the full arguments dict
  4. Guard the call site by diffing required names against your dict keys before rendering

Example fix

// before
await prompt.render({})
// after
await prompt.render({'code': 'def foo(): pass', 'language': 'python'})
Defensive patterns

Strategy: validation

Validate before calling

required = {a.name for a in prompt.arguments if a.required}
missing = required - set(arguments or {})
if missing:
    raise ValueError(f'cannot render prompt, missing: {missing}')
result = prompt.render(arguments)

Try / catch

try:
    result = prompt.render(arguments)
except ValueError as e:
    logger.warning('prompt arguments rejected: %s', e)
    result = None

Prevention

When it happens

Trigger: Calling prompt.render(arguments) (or via a client prompts.get_prompt) while omitting a declared-required PromptArgument, e.g. arguments spec has PromptArgument(name='code', required=True) but render({'other': 'x'}) is called, or render() is called with arguments=None.

Common situations: Client code omits optional-looking params; a prompt was refactored to add a new required argument and existing callers weren't updated; LLM clients send partial arguments from a template; passing {'code': None} keeps the key in the provided set so this check passes but the fn may fail later.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29). Data as JSON: /api/errors/a3d1db1ebea7b295. Report an issue: GitHub.