Structured Outputs
Last updated
Was this helpful?
Last updated
Was this helpful?
Structured Outputs ensure that the model always follows your supplied . Portkey supports OpenAI's Structured Outputs feature out of the box with our SDKs & APIs.
Portkey SDKs for and also make it easy to define object schemas using and 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.
If you are connecting the model to tools, functions, data, etc. in your system, then you should use function calling.
And if you want to structure the model's output when it responds to the user, then you should use a structured response_format
.
In response_format
, you can set it as { "type": "json_object" }
to enable the .
And you can set it as { "type": "json_schema" }
to use the .
For more, refer to OpenAI's .