{"record":{"id":"a3527b794d094c32","repo":"microsoft/semantic-kernel","slug":"invalid-arguments","errorCode":null,"errorMessage":"Invalid arguments","messagePattern":"Invalid arguments","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/runtime/core/routed_agent.py","lineNumber":177,"sourceCode":"                if strict:\n                    raise ValueError(f\"Return type {type(return_value)} not in return types {return_types}\")\n                logger.warning(f\"Return type {type(return_value)} not in return types {return_types}\")\n\n            return return_value\n\n        wrapper_handler = cast(MessageHandler[AgentT, ReceivesT, ProducesT], wrapper)\n        wrapper_handler.target_types = list(target_types)\n        wrapper_handler.produces_types = list(return_types)\n        wrapper_handler.is_message_handler = True\n        wrapper_handler.router = match or (lambda _message, _ctx: True)\n\n        return wrapper_handler\n\n    if func is None and not callable(func):\n        return decorator\n    if callable(func):\n        return decorator(func)\n    raise ValueError(\"Invalid arguments\")\n\n\n# endregion\n\n# region Message Handler Decorators\n\n\n@experimental\n@overload\ndef event(\n    func: Callable[[AgentT, ReceivesT, MessageContext], Coroutine[Any, Any, None]],\n) -> MessageHandler[AgentT, ReceivesT, None]: ...\n\n\n@experimental\n@overload\ndef event(\n    func: None = None,","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/runtime/core/routed_agent.py#L159-L195","documentation":"Raised at the bottom of the @message_handler decorator when the first positional argument (func) is neither None nor callable. The decorator supports both bare (@message_handler) and direct (@message_handler(func)) usage; any other first argument is a misuse.","triggerScenarios":"Calling message_handler with a non-callable first positional argument, e.g. @message_handler(some_string) or message_handler(123). Also reachable via unusual decorator stacking that passes a non-callable.","commonSituations":"Mistakenly passing decorator options as the first positional instead of via keyword args; misusing the decorator factory form; accidentally invoking message_handler(value) instead of message_handler()(value).","solutions":["Use the bare form @message_handler on the method, or keyword args for options.","If passing options, use @message_handler(strict=False, match=...) without a positional func.","Do not pass a string/int/object as the first positional argument.","Check that any variable passed positionally is actually the method being decorated."],"exampleFix":"// before\n@message_handler(\"MyMsg\")\nasync def handle(self, message, ctx): ...\n// after\n@message_handler\nasync def handle(self, message: MyMsg, ctx: MessageContext) -> None: ...","handlingStrategy":"validation","validationCode":"from collections.abc import Callable\n\ndef is_valid_handler_decorator_arg(func) -> bool:\n    return func is None or callable(func)","typeGuard":"from collections.abc import Callable\nfrom typing import Any\n\ndef is_callable_or_none(value: Any) -> bool:\n    return value is None or callable(value)","tryCatchPattern":null,"preventionTips":["Use the bare @message_handler form on methods.","Pass options as keyword args, not positional non-callables.","Do not pass strings/ints as the first positional argument.","Double-check decorator factory usage when stacking decorators."],"tags":["runtime","decorators","message-handler","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}