I have an MCP server that I am trying to use in conjunction with openAI responses API via openai.response.parse. I am trying to use the tool to get a certain output, then have the ai consider that output before making the final output in a certain json schema. It works whenever I use text: format: ‘text’, however when I try to put in a json_schema, it breaks, calling the tool over and over, sometimes repeating in sequence, sometimes repeating the same empty call, and stopping after 20 tool calls and not returning anything past that. I have tried using openAI Playground, and found that it works when I put in an identical schema, and set the settings to all the same that are in my call to openai.response.parse. What could be the difference between openAI playground and calling in code? Any ideas on what could be causing this issue? I thought it could be a mismatch of the output and the json_schema, but I have in my prompt
Expected Output:
{
"example_property1": [],
"example_property2": ["example", "example"],
"example_property3": ["example", "example"],
"example_property4": "example"
}
which (I think) exactly matches the json schema. Any ideas or help would be greatly appreciated.
For reference here is my call
response = await openai.responses.parse({
metadata: metadata ?? {},
input: query,
max_output_tokens: MAX_OUTPUT_TOKENS,
model: 'gpt-4o-mini',
reasoning: reasoningEffort
? {
effort: reasoningEffort
}
: undefined,
store: true,
temperature,
text: {
format: {
name: 'example_name',
schema: {
additionalProperties: false,
properties: {
example_property1: {
items: {
type: 'string'
},
type: 'array'
},
example_property2: {
items: {
type: 'string'
},
type: 'array'
},
example_property3: {
items: {
type: 'string'
},
type: 'array'
},
example_property4: {
type: 'string'
}
},
required: ['example_property1', 'example_property2', 'example_property3', 'example_property4'],
type: 'object'
},
strict: true,
type: 'json_schema'
}
},
tool_choice: 'auto',
tools: [
...(mcpServer
? [
{
headers: {
[CORE_PLATFORM_API_HEADER_KEY]: process.env.CORE_PLATFORM_API_KEY ?? ''
},
require_approval: 'never' as const,
server_label: mcpServer.label,
server_url: `https://example.app/api/mcp`,
type: 'mcp' as const
}
]
: []),
...(allowAgentToSearch
? [
{
search_context_size: contextSize,
type: 'web_search_preview' as const,
user_location: US_USER_LOCATION
}
]
: [])
] satisfies (Tool.Mcp | WebSearchTool)[],
top_p: 1
});