{"record":{"id":"31d1add99228248f","repo":"microsoft/semantic-kernel","slug":"no-variable-found-in-context-to-use-as-an-argument","errorCode":null,"errorMessage":"No variable found in context to use as an argument for the `{parameter.name}` parameter of the `{plugin_name}.{operation.id}` REST function.","messagePattern":"No variable found in context to use as an argument for the `(.+?)` parameter of the `(.+?)\\.(.+?)` REST function\\.","errorType":"exception","errorClass":"FunctionExecutionException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/openapi_plugin/openapi_manager.py","lineNumber":152,"sourceCode":"    ) -> str:\n        try:\n            kernel_arguments = KernelArguments()\n\n            for parameter in rest_operation_params:\n                if parameter.alternative_name and parameter.alternative_name in kwargs:\n                    value = kwargs[parameter.alternative_name]\n                    if value is not None:\n                        kernel_arguments[parameter.name] = value\n                        continue\n\n                if parameter.name in kwargs:\n                    value = kwargs[parameter.name]\n                    if value is not None:\n                        kernel_arguments[parameter.name] = value\n                        continue\n\n                if parameter.is_required:\n                    raise FunctionExecutionException(\n                        f\"No variable found in context to use as an argument for the \"\n                        f\"`{parameter.name}` parameter of the `{plugin_name}.{operation.id}` REST function.\"\n                    )\n\n            options = RestApiRunOptions(\n                server_url_override=(\n                    execution_parameters.server_url_override\n                    if execution_parameters and execution_parameters.server_url_override is not None\n                    else None\n                ),\n                api_host_url=Uri(document_uri).get_left_part() if document_uri is not None else None,\n                timeout=execution_parameters.timeout\n                if execution_parameters and execution_parameters.timeout is not None\n                else None,\n            )\n\n            return await runner.run_operation(operation, kernel_arguments, options)\n        except Exception as e:","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/openapi_plugin/openapi_manager.py#L134-L170","documentation":"When the generated REST function is invoked, each parameter is resolved from `kwargs` by `alternative_name` then `name`. If a parameter `is_required` and neither key yields a non-None value, `FunctionExecutionException` is raised naming the parameter and the `plugin.operation`. Optional parameters with no argument are simply skipped.","triggerScenarios":"Invoking the kernel function (e.g. via `kernel.invoke`) without passing a required argument; passing it under a different name than `alternative_name`/`name`; passing `None` explicitly for a required parameter; argument-name mismatch after a spec rename.","commonSituations":"Prompt/function-calling omits a required slot; the caller uses the OpenAPI parameter name while the kernel expects the `alternative_name` (or vice versa); a refactor renamed a parameter but callers were not updated; required path/query params not surfaced by the model.","solutions":["Pass the missing required argument under the parameter's `alternative_name` (preferred) or `name`.","Inspect the function's `parameters` metadata to see the exact expected argument names.","Make the parameter optional in the spec (or supply a `default`) if it can be omitted.","Provide a wrapper that pre-fills defaults for required args before invoking."],"exampleFix":"# before\nresult = await kernel.invoke(pet_fn, KernelArguments())  # raises 1487 (missing 'petId')\n\n# after\nfrom semantic_kernel.functions import KernelArguments\nresult = await kernel.invoke(pet_fn, KernelArguments(petId=42))","handlingStrategy":"validation","validationCode":"def required_args_supplied(fn, kwargs) -> None:\n    missing = [\n        (p.alternative_name or p.name)\n        for p in fn.parameters\n        if p.is_required and kwargs.get(p.alternative_name or p.name) is None\n    ]\n    if missing:\n        raise ValueError(f\"Missing required arguments: {missing}\")\n\nrequired_args_supplied(rest_fn, kwargs)\nawait kernel.invoke(rest_fn, KernelArguments(**kwargs))","typeGuard":"def is_required_param(p) -> bool:\n    return bool(getattr(p, \"is_required\", False))","tryCatchPattern":"from semantic_kernel.exceptions import FunctionExecutionException\n\ntry:\n    result = await kernel.invoke(rest_fn, KernelArguments(**kwargs))\nexcept FunctionExecutionException as e:\n    if \"No variable found in context\" in str(e):\n        # extract expected param, fill it, retry once\n        raise\n    raise","preventionTips":["Inspect `fn.parameters` to learn exact required argument names.","Pre-fill required defaults in your wrapper before invoking.","Pass arguments under the parameter's `alternative_name` when set.","Add a pre-flight check that all required args are non-None."],"tags":["openapi-plugin","invocation","arguments","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}