{"record":{"id":"9eb62af0a811ffb0","repo":"microsoft/semantic-kernel","slug":"tool-spec-must-include-a-type-field-9eb62a","errorCode":null,"errorMessage":"Tool spec must include a 'type' field.","messagePattern":"Tool spec must include a 'type' field\\.","errorType":"exception","errorClass":"AgentInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/openai_assistant_agent.py","lineNumber":121,"sourceCode":"# Update _code_interpreter\n@_register_tool(\"code_interpreter\")\ndef _code_interpreter(spec: ToolSpec, kernel: Kernel | None = None) -> tuple[list[AssistantToolParam], ToolResources]:\n    file_ids = spec.options.get(\"file_ids\")\n    return OpenAIAssistantAgent.configure_code_interpreter_tool(file_ids=file_ids)\n\n\n# Update _file_search\n@_register_tool(\"file_search\")\ndef _file_search(spec: ToolSpec, kernel: Kernel | None = None) -> tuple[list[AssistantToolParam], ToolResources]:\n    vector_store_ids = spec.options.get(\"vector_store_ids\")\n    if not vector_store_ids or not isinstance(vector_store_ids, list) or not vector_store_ids[0]:\n        raise AgentInitializationException(f\"Missing or malformed 'vector_store_ids' in: {spec}\")\n    return OpenAIAssistantAgent.configure_file_search_tool(vector_store_ids=vector_store_ids)\n\n\ndef _build_tool(spec: ToolSpec, kernel: \"Kernel\") -> tuple[list[AssistantToolParam], ToolResources]:\n    if not spec.type:\n        raise AgentInitializationException(\"Tool spec must include a 'type' field.\")\n\n    try:\n        builder = _TOOL_BUILDERS[spec.type.lower()]\n    except KeyError as exc:\n        raise AgentInitializationException(f\"Unsupported tool type: {spec.type}\") from exc\n\n    sig = inspect.signature(builder)\n    return builder(spec) if len(sig.parameters) == 1 else builder(spec, kernel)  # type: ignore[call-arg]\n\n\n# endregion\n\n\n@release_candidate\nclass AssistantAgentThread(AgentThread):\n    \"\"\"An OpenAI Assistant Agent Thread class.\"\"\"\n\n    def __init__(","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/openai_assistant_agent.py#L103-L139","documentation":"Raised by _build_tool when a ToolSpec has no 'type' field (type is None or empty). The tool dispatcher keys builders by spec.type.lower(), so a missing type means it cannot select a builder and fails fast rather than producing a confusing KeyError.","triggerScenarios":"Constructing a ToolSpec without setting type, or loading a declarative spec YAML where a tool entry omits the 'type' key.","commonSituations":"Hand-building ToolSpec(...) and forgetting type; malformed YAML spec missing the type field; deserializing partial data where type defaulted to None.","solutions":["Set ToolSpec.type to a supported tool type (e.g. 'code_interpreter' or 'file_search').","Validate the declarative spec: every tool entry must include a 'type' key.","If loading from YAML/dict, assert 'type' is present and non-empty before constructing ToolSpec."],"exampleFix":"# before\ntool = ToolSpec(options={\"file_ids\": [\"file_1\"]})  # no type\n# after\ntool = ToolSpec(type=\"code_interpreter\", options={\"file_ids\": [\"file_1\"]})","handlingStrategy":"validation","validationCode":"if not getattr(spec, \"type\", None):\n    raise ValueError(\"ToolSpec.type must be set (e.g. 'code_interpreter' or 'file_search').\")","typeGuard":"def has_tool_type(spec) -> bool:\n    return bool(getattr(spec, \"type\", None))","tryCatchPattern":null,"preventionTips":["Always set ToolSpec.type when constructing tools programmatically.","When loading declarative specs, validate every tool entry has a non-empty 'type'.","Add a schema check (pydantic/jsonschema) for spec files."],"tags":["openai","semantic-kernel","agents","tools","declarative-spec","validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}