JSON mode returning invalid JSON with nested objects
When using response_format: { type: "json_object" } with deeply nested schemas, GPT-4o sometimes returns invalid JSON. This doesn't happen with Structured Outputs, only the older JSON mode.
response = client.chat.completions.create(
model="gpt-4o",
messages=[{
"role": "user",
"content": "Generate a nested config with 4 levels deep"
}],
response_format={"type": "json_object"}
)Sometimes returns truncated JSON like:
{"config": {"level1": {"level2": {"level3": {"level4":
This seems to happen when the output would be close to max_tokens. The model doesn't properly close all brackets before stopping.
Yes, this works! Each assistant can see all messages in the thread, including messages generated by other assistants. This is a supported pattern for multi-agent workflows.
Key tip: set the additional_instructions parameter on each run to give the assistant its specific role context without modifying the assistant's base instructions.
No hard limit on the number of different assistants per thread. The limiting factor is the context window — each run processes the full thread history.
Log in to reply to this topic.