This feature is available for
Gemini 1.5 Pro
& Gemini 1.5 Flash
models.With Pydantic & Zod
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.- Pydantic with Python
- Zod with NodeJS
Using Enums
You can also use enums to constrain the model’s output to a predefined set of values. This is particularly useful for classification tasks and multiple choice responses.- Python with Enums
Using JSON schema Directly
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.- NodeJS
- Python
- cURL