Skip to content

fix(core): accept JSON Schema type arrays of object for tool outputs - #4647

Merged
seratch merged 1 commit into
openai:mainfrom
hsusul:fix/function-tool-output-schema-object-type-array
Aug 25, 2026
Merged

seratch merged 1 commit into
openai:mainfrom
hsusul:fix/function-tool-output-schema-object-type-array

Conversation

@hsusul

@hsusul hsusul commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

_json_schema_is_object() only treated \"type\": \"object\" as an object schema. JSON Schema also allows a one-element type array (\"type\": [\"object\"]), which OpenAPI and MCP generators commonly emit.

That form already works for params because ensure_strict_json_schema / _ensure_strict_root normalize it. The output path checks _json_schema_is_object first, so function_tool(..., output_json_schema={\"type\": [\"object\"], ...}) raised UserError before conversion.

Reproduction

from agents import function_tool

schema = {
    \"type\": [\"object\"],
    \"properties\": {\"a\": {\"type\": \"string\"}},
    \"required\": [\"a\"],
    \"additionalProperties\": False,
}

function_tool(lambda: {\"a\": \"x\"}, allowed_callers=[\"programmatic\"], output_json_schema=schema)
# Before: UserError: output_json_schema must define a JSON object schema.
# After: accepted and stored with type == \"object\"

Solution

Treat type == [\"object\"] as an object, matching _ensure_strict_root. Other type arrays such as [\"object\", \"null\"] still fail the object gate / strict conversion.

Test plan

  • Added a programmatic-tool regression that constructs a tool from type: [\"object\"]
  • uv run pytest tests/test_programmatic_tool_calling.py tests/test_function_tool.py (202 passed)
  • make format, make lint, make typecheck passed
  • Full make tests: 9193 passed, 1 pre-existing failure in tests/sandbox/test_run_cwd.py::test_python_skill_uses_absolute_root_from_nested_workdir (reproduced on unmodified main)

Issue number

N/A

Checks

  • I've added new tests, if relevant
  • I've run format, lint, typecheck, and targeted tests
  • If using Codex, I've run /review before submitting this PR

Programmatic tools rejected output_json_schema values that used
type: ["object"], a form JSON Schema, OpenAPI, and MCP generators emit.
The params and strict-schema paths already treat that as an object.
@seratch seratch changed the title fix(tools): accept JSON Schema type arrays of object for tool outputs fix(core): accept JSON Schema type arrays of object for tool outputs Aug 25, 2026
@seratch
seratch enabled auto-merge (squash) August 25, 2026 06:23
@seratch
seratch disabled auto-merge August 25, 2026 06:23
@seratch seratch added this to the 0.22.x milestone Aug 25, 2026
@seratch
seratch merged commit 1cd8303 into openai:main Aug 25, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants