Skip to content

Feature Request: Support Gemini Structured Output #871

@mzazakeith

Description

@mzazakeith

Summary

Enable Praison AI to generate structured output (such as JSON or enums) using Gemini models, not just OpenAI models. This will allow users to extract and standardize information in a machine-readable format directly from Gemini, leveraging its native structured output capabilities.

Motivation

  • Consistent Experience: Users can obtain structured data (e.g., JSON) from both OpenAI and Gemini models, making it easier to build pipelines and automate downstream processing.
  • Advanced Extraction: Gemini’s structured output allows for precise extraction of information, such as from resumes, articles, or forms, directly into standardized formats.
  • Schema Enforcement: By configuring a response schema, users can constrain Gemini to output data in a specific structure, improving reliability and reducing post-processing.

Example Usage

Python Example:

from google import genai
from pydantic import BaseModel

class Recipe(BaseModel):
    recipe_name: str
    ingredients: list[str]

client = genai.Client()
response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="List a few popular cookie recipes, and include the amounts of ingredients.",
    config={
        "response_mime_type": "application/json",
        "response_schema": list[Recipe],
    },
)
print(response.text)  # JSON string
print(response.parsed)  # List[Recipe] objects
  • You can also use JSON Schema for more complex or custom structures.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions