Structured Outputs ensure that the model always follows your supplied JSON schema. Portkey supports OpenAI’s Structured Outputs feature out of the box with our SDKs & APIs.
Structured Outputs is different from OpenAI’s JSON Mode
as well as Function Calling
. Check out this table for a quick comparison.
Portkey SDKs for Python and JavaScript also make it easy to define object schemas using Pydantic and Zod respectively. Below, you can see how to extract information from unstructured text that conforms to a schema defined in code.
The second approach, shown in the subsequent examples, uses a JSON schema directly in the API call. This method is more portable across different languages and doesn’t require additional libraries, but lacks the integrated type checking of the Pydantic/Zod approach. Choose the method that best fits your project’s needs and language ecosystem.
response_format
.
response_format
, you can set it as { "type": "json_object" }
to enable the JSON Mode.{ "type": "json_schema" }
to use the Structured Outputs Mode described above.For more, refer to OpenAI’s detailed documentation on Structured Outputs here.