Back to Discover

#json schema

2 prompts found

Gemini API Structured Output Schema Builder: response_mime_type JSON, response_schema from Pydantic, Enums, propertyOrdering, Nullable Fields, and Validation Retries
🤖 AI Tools

Gemini API Structured Output Schema Builder: response_mime_type JSON, response_schema from Pydantic, Enums, propertyOrdering, Nullable Fields, and Validation Retries

Ppromptstudio·Oct 9, 2026
No rating

Design a Gemini API structured output setup for an extraction or classification job: the schema in the subset Gemini accepts, the google-genai Python config, enum and nullable handling, field order that keeps reasoning before answers, and a validation and retry plan for bad responses.

Act as an LLM application engineer who builds production extraction pipelines on the Gemini API, knows which JSON schema features Gemini structured output supports, and ships schemas that parse on the first try. Inputs: - The task: what goes in (document type, length, language) and what must come out: [ExtractionTask] - Fields you need, with type, allowed values, required or optional, and an example value: [FieldList] - Model and SDK: Gemini model name, google-genai Python or JS SDK version, Vertex AI or Gemini Developer API: [ModelAndSDK] - Sample documents or snippets, including a messy or incomplete one: [SampleDocs] - Downstream consumer: database table, Pydantic model, or API that reads the JSON: [Downstream] - Output format: [Format] Generate: 1. A schema design table from FieldList: field, Gemini schema type, enum values, nullable, required, and description text that tells the model how to fill it. 2. A Pydantic model (or TypeScript type if ModelAndSDK uses JS) that maps to Downstream, kept to schema features Gemini structured output accepts, with unsupported features (for example complex conditional keywords) replaced by simpler patterns and marked [confirm in current Gemini docs]. 3. The google-genai request config: response_mime_type set to application/json and response_schema set to the model, plus the system instruction. 4. Field ordering: put evidence or source quote fields before the answer fields and set propertyOrdering where the SDK needs it, so the model writes support before conclusions. 5. Null and enum rules: when to return null instead of guessing, an "unknown" enum value where a category may not apply, and a single text/x.enum option if the job is pure classification. 6. A test run plan over SampleDocs: expected JSON for each, including the messy one. 7. Validation and retry: parse with the Pydantic model, what to do on a validation error (retry once with the error message, then route to human review), and what to log. 8. A short cost and size note: keep descriptions short, cap list lengths, and avoid deep nesting. Constraints: - Do not invent SDK parameters; when unsure of a name or limit in ModelAndSDK, write [confirm in current Gemini docs]. - Never make up field values in examples beyond SampleDocs. - Code first, short explanations. No em dashes.

OpenAI Structured Outputs Schema Designer: JSON Schema Strict Mode, Refusal Paths, Pydantic Models, and Evaluation Fixtures
🤖 AI Tools

OpenAI Structured Outputs Schema Designer: JSON Schema Strict Mode, Refusal Paths, Pydantic Models, and Evaluation Fixtures

Ppromptstudio·Oct 8, 2026
No rating

Design an OpenAI Structured Outputs setup for a production extractor: a strict JSON Schema, matching Pydantic models, refusal and incompleteness paths, and a small fixture set so you can regression test parsing before you wire the schema into the API.

Act as an applied LLM engineer who ships OpenAI Structured Outputs in strict mode, writes JSON Schema that mirrors Pydantic models, and builds tiny evaluation fixtures before production traffic. Inputs: - Extraction or routing job the model must do: [JobBrief] - Fields that must always appear, optional fields, and enums: [FieldSpec] - Model family you plan to call (name only, no invented version guarantees): [ModelFamily] - Failure modes you have already seen (hallucinated IDs, empty arrays, wrong enum): [FailureModes] - Runtime language (Python Pydantic v2, TypeScript Zod, or JSON Schema only): [Runtime] - Output format: [Format] Generate: 1. A JSON Schema draft with "$schema", "type":"object", "additionalProperties": false, required arrays, and typed properties matching FieldSpec. 2. Strict mode notes: which fields are required vs nullable, and how to represent "unknown" without inventing data. 3. A parallel model in Runtime (Pydantic v2 or Zod) that matches the schema field for field. 4. Tool or response_format wiring sketch using ModelFamily with placeholders for API parameters you are unsure of marked [confirm in OpenAI docs]. 5. Refusal and incompleteness paths: when the model should return a structured error object instead of guessing, with a separate small schema or a status enum inside the main schema. 6. Evaluation fixtures: 3 input snippets and the exact expected JSON objects, plus 1 adversarial input tied to FailureModes. 7. A validation snippet outline: parse, catch schema errors, retry once with a repair instruction, then fail closed. 8. A changelog line for the schema version so product can bump without silent breaks. Constraints: - Do not invent token prices, rate limits, or model release dates. - Prefer enums over free text for categories the product already knows. - Honesty: at most one step that refuses to invent missing identifiers. - No em dashes.