{"record":{"id":"e4d2ecef52033eb8","repo":"microsoft/semantic-kernel","slug":"could-not-generate-schema-for-the-type-response-f","errorCode":null,"errorMessage":"Could not generate schema for the type {response_format}.","messagePattern":"Could not generate schema for the type (.+?)\\.","errorType":"exception","errorClass":"AgentInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/openai_responses_agent.py","lineNumber":801,"sourceCode":"                f\"Encountered unexpected response_format type: {resp_type}. Allowed types are `json_object` \"\n                \" and `json_schema`.\"\n            )\n        if isinstance(response_format, type):\n            if issubclass(response_format, BaseModel):\n                interim_format = type_to_text_format_param(response_format)\n                if interim_format[\"type\"] != \"json_schema\":\n                    raise AgentInitializationException(\"Only 'json_schema' is allowed from that helper.\")\n                configured_format = {\n                    \"type\": \"json_schema\",\n                    \"name\": interim_format.get(\"name\", response_format.__name__),\n                    \"schema\": interim_format.get(\"schema\"),\n                    \"strict\": interim_format.get(\"strict\", True),\n                }\n            else:\n                # Build a schema from a plain Python class\n                generated_schema = KernelJsonSchemaBuilder.build(parameter_type=response_format, structured_output=True)\n                if generated_schema is None:\n                    raise AgentInitializationException(f\"Could not generate schema for the type {response_format}.\")\n                configured_format = {\n                    \"type\": \"json_schema\",\n                    \"name\": response_format.__name__,\n                    \"schema\": generated_schema,\n                    \"strict\": True,\n                }\n        else:\n            raise AgentInitializationException(\n                \"response_format must be a dictionary, a subclass of BaseModel, a Python class/type, or None\"\n            )\n\n        return {\"format\": configured_format}\n\n    # endregion\n\n    # region Invocation Methods\n\n    @trace_agent_get_response","sourceCodeStart":783,"sourceCodeEnd":819,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/openai_responses_agent.py#L783-L819","documentation":"Raised by configure_response_format() on the plain-Python-class branch when KernelJsonSchemaBuilder.build(parameter_type=response_format, structured_output=True) returns None. The builder returns None when it cannot derive a JSON schema for the given type, so the method cannot construct a structured output envelope.","triggerScenarios":"Passing a plain Python class/type (not a pydantic BaseModel) whose annotations or structure the KernelJsonSchemaBuilder cannot introspect — e.g. a class with no type-annotated fields, dynamic/Generated types, or types the builder explicitly skips.","commonSituations":"Using a dataclass or TypedDict the schema builder doesn't support, a class with untyped attributes, or passing a builtin/abstract type. The builder yields None rather than a partial/invalid schema.","solutions":["Convert the class to a pydantic BaseModel (preferred — uses the BaseModel branch and the openai helper).","Ensure all fields have type annotations the builder understands.","Build the JSON schema yourself and pass it via the dict path with type 'json_schema'.","Log KernelJsonSchemaBuilder.build(...) in isolation to see why it returns None."],"exampleFix":"// before\nclass Out:\n    value = None  # no annotation\ncfg = OpenAIResponsesAgent.configure_response_format(Out)\n\n// after\nfrom pydantic import BaseModel\nclass Out(BaseModel):\n    value: str\ncfg = OpenAIResponsesAgent.configure_response_format(Out)","handlingStrategy":"validation","validationCode":"from semantic_kernel.schema.kernel_json_schema_builder import KernelJsonSchemaBuilder\nschema = KernelJsonSchemaBuilder.build(parameter_type=response_format, structured_output=True)\nif schema is None:\n    raise ValueError('Cannot derive schema; convert to BaseModel or supply dict')","typeGuard":"def type_has_schema(t: type) -> bool:\n    from semantic_kernel.schema.kernel_json_schema_builder import KernelJsonSchemaBuilder\n    return KernelJsonSchemaBuilder.build(parameter_type=t, structured_output=True) is not None","tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInitializationException\ntry:\n    cfg = OpenAIResponsesAgent.configure_response_format(MyClass)\nexcept AgentInitializationException as e:\n    if 'generate schema' in str(e):\n        from pydantic import BaseModel\n        class MyModel(BaseModel):\n            ...  # mirror MyClass\n        cfg = OpenAIResponsesAgent.configure_response_format(MyModel)\n    raise","preventionTips":["Prefer pydantic BaseModel over plain classes for structured output.","Ensure all fields are type-annotated with schema-compatible types.","Smoke-test KernelJsonSchemaBuilder.build() on your type before wiring it in."],"tags":["response-format","json-schema","schema-builder"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}