With the SDKs
Pass a Pydantic model asanswer_schema or a Zod v4 schema as answerSchema. The SDK derives the JSON Schema, sends it, and parses the final answer into a typed instance.
With a JSON Schema
Without an SDK, set a JSON Schema asanswer_format on the agent, or per run with the agent.answer_format override. The settled answer (latest_answer on the session, answer on changes) is a JSON object matching it.
error_code: answer_validation.