Skip to main content
Controlled Generations allows you to constrain model responses to predefined sets of values. This is particularly useful for classification tasks, multiple choice responses, and structured data extraction.
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.

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.

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.
For more, refer to Google Vertex AI’s detailed documentation on Controlled Generations here.
Last modified on April 8, 2026