I’m getting a vague error when using structured output with the Responses API. My output is a Pydantic object:
class WidgetAgentOutput(BaseModel):
widgets: list[OutputWidgetOneOf]
should_run_thinker_agent: bool
bounce_text: str
Where OutputWidgetOneOf is a union of different config options, for example:
class GameOverviewWidgetSpec(OutputWidgetSpec):
league: LeagueId
game_id: str
OutputWidgetOneOf = (
SingleEntityStatsWidgetSpec
| MultiEntityStatsWidgetSpec
| SingleEntityOddsWidgetSpec
| MultiEntityOddsWidgetSpec
| GameOverviewWidgetSpec
| MlbStadiumWeatherWidgetSpec
)
The error is very unhelpful:
{
"error": "Error code: 400 - {'error': {'message': 'There was an issue with your request. Please check your inputs and try again', 'type': 'invalid_request_error', 'param': None, 'code': None}}"
}
Which is the result of running both the Agents SDK and the Responses API directly.
widget_agent = Agent(
name="Widget Agent",
model="gpt-4.1-mini",
instructions=PROMPT,
output_type=WidgetAgentOutput,
tools=[
lookup_player,
lookup_team,
get_current_season,
get_league_market_specs,
],
)
For reference, here is the full generated JSON output schema:
{
"format": {
"type": "json_schema",
"name": "final_output",
"schema": {
"$defs": {
"GameEntityId": {
"description": "A game ID and entity ID pair",
"properties": {
"game_id": {
"title": "Game Id",
"type": "string"
},
"entity_id": {
"title": "Entity Id",
"type": "string"
}
},
"required": [
"game_id",
"entity_id"
],
"title": "GameEntityId",
"type": "object",
"additionalProperties": false
},
"GameOverviewWidgetSpec": {
"properties": {
"id": {
"$ref": "#/$defs/WidgetId"
},
"league": {
"enum": [
"nfl",
"ncaafb",
"nhl",
"nba",
"wnba",
"ncaamb",
"mlb",
"mls",
"epl",
"laliga",
"bundesliga",
"serie_a",
"ucl",
"ligue_1",
"all_soccer"
],
"title": "League",
"type": "string"
},
"game_id": {
"title": "Game Id",
"type": "string"
}
},
"required": [
"id",
"league",
"game_id"
],
"title": "GameOverviewWidgetSpec",
"type": "object",
"additionalProperties": false
},
"MlbStadiumWeatherWidgetSpec": {
"properties": {
"id": {
"$ref": "#/$defs/WidgetId"
},
"game_id": {
"title": "Game Id",
"type": "string"
}
},
"required": [
"id",
"game_id"
],
"title": "MlbStadiumWeatherWidgetSpec",
"type": "object",
"additionalProperties": false
},
"MultiEntityOddsWidgetSpec": {
"properties": {
"id": {
"$ref": "#/$defs/WidgetId"
},
"league": {
"enum": [
"nfl",
"ncaafb",
"nhl",
"nba",
"wnba",
"ncaamb",
"mlb",
"mls",
"epl",
"laliga",
"bundesliga",
"serie_a",
"ucl",
"ligue_1",
"all_soccer"
],
"title": "League",
"type": "string"
},
"game_and_entity_ids": {
"items": {
"$ref": "#/$defs/GameEntityId"
},
"title": "Game And Entity Ids",
"type": "array"
},
"market_ids": {
"items": {
"type": "string"
},
"title": "Market Ids",
"type": "array"
}
},
"required": [
"id",
"league",
"game_and_entity_ids",
"market_ids"
],
"title": "MultiEntityOddsWidgetSpec",
"type": "object",
"additionalProperties": false
},
"MultiEntityStatsWidgetSpec": {
"properties": {
"id": {
"$ref": "#/$defs/WidgetId"
},
"league": {
"enum": [
"nfl",
"ncaafb",
"nhl",
"nba",
"wnba",
"ncaamb",
"mlb",
"mls",
"epl",
"laliga",
"bundesliga",
"serie_a",
"ucl",
"ligue_1",
"all_soccer"
],
"title": "League",
"type": "string"
},
"entity_ids": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"title": "Entity Ids"
},
"split_strings": {
"items": {
"type": "string"
},
"title": "Split Strings",
"type": "array"
}
},
"required": [
"id",
"league",
"entity_ids",
"split_strings"
],
"title": "MultiEntityStatsWidgetSpec",
"type": "object",
"additionalProperties": false
},
"SingleEntityOddsWidgetSpec": {
"properties": {
"id": {
"$ref": "#/$defs/WidgetId"
},
"league": {
"enum": [
"nfl",
"ncaafb",
"nhl",
"nba",
"wnba",
"ncaamb",
"mlb",
"mls",
"epl",
"laliga",
"bundesliga",
"serie_a",
"ucl",
"ligue_1",
"all_soccer"
],
"title": "League",
"type": "string"
},
"game_id": {
"title": "Game Id",
"type": "string"
},
"entity_id": {
"title": "Entity Id",
"type": "string"
},
"market_ids": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"title": "Market Ids"
}
},
"required": [
"id",
"league",
"game_id",
"entity_id",
"market_ids"
],
"title": "SingleEntityOddsWidgetSpec",
"type": "object",
"additionalProperties": false
},
"SingleEntityStatsWidgetSpec": {
"properties": {
"id": {
"$ref": "#/$defs/WidgetId"
},
"league": {
"enum": [
"nfl",
"ncaafb",
"nhl",
"nba",
"wnba",
"ncaamb",
"mlb",
"mls",
"epl",
"laliga",
"bundesliga",
"serie_a",
"ucl",
"ligue_1",
"all_soccer"
],
"title": "League",
"type": "string"
},
"entity_id": {
"title": "Entity Id",
"type": "string"
},
"split_strings": {
"items": {
"type": "string"
},
"title": "Split Strings",
"type": "array"
}
},
"required": [
"id",
"league",
"entity_id",
"split_strings"
],
"title": "SingleEntityStatsWidgetSpec",
"type": "object",
"additionalProperties": false
},
"WidgetId": {
"enum": [
"single_entity_stats",
"multi_entity_stats",
"single_entity_odds",
"multi_entity_odds",
"game_overview",
"mlb_stadium_weather"
],
"title": "WidgetId",
"type": "string"
}
},
"properties": {
"widgets": {
"items": {
"anyOf": [
{
"$ref": "#/$defs/SingleEntityStatsWidgetSpec"
},
{
"$ref": "#/$defs/MultiEntityStatsWidgetSpec"
},
{
"$ref": "#/$defs/SingleEntityOddsWidgetSpec"
},
{
"$ref": "#/$defs/MultiEntityOddsWidgetSpec"
},
{
"$ref": "#/$defs/GameOverviewWidgetSpec"
},
{
"$ref": "#/$defs/MlbStadiumWeatherWidgetSpec"
}
]
},
"title": "Widgets",
"type": "array"
},
"should_run_thinker_agent": {
"title": "Should Run Thinker Agent",
"type": "boolean"
},
"bounce_text": {
"title": "Bounce Text",
"type": "string"
}
},
"required": [
"widgets",
"should_run_thinker_agent",
"bounce_text"
],
"title": "WidgetAgentOutput",
"type": "object",
"additionalProperties": false
},
"strict": true
}
}