Generative AI Leader Fundamentals of Generative AI Practice Question
A developer uses the Vertex AI Python SDK to call a Gemini model for structured JSON output. However, the model often returns malformed JSON. Which parameter should the developer set in the generation configuration to enforce valid JSON output?
⚠ Common exam trap
Google Cloud often tests the misconception that prompt engineering (e.g., few-shot examples or temperature tuning) can reliably enforce structured output, when in fact the correct approach is to use the API's native structured output parameter like `response_mime_type`.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Set the 'response_mime_type' parameter to 'application/json'.
Setting `response_mime_type` to `'application/json'` in the generation configuration instructs the Gemini API to constrain the model's output to valid JSON format. This parameter leverages the model's native structured output capability, ensuring the response adheres to JSON syntax without relying on post-processing or prompt engineering.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Set the temperature to a lower value (0.1) to reduce variation.
Why it's wrong here
Temperature controls sampling randomness, so lowering it makes outputs more deterministic but still free-form text; it cannot enforce JSON syntax. The response schema or MIME type setting constrains decoding to valid JSON. Temperature is the correct control when you want consistent, less varied prose.
- ✓
Set the 'response_mime_type' parameter to 'application/json'.
Why this is correct
Setting `response_mime_type` to `application/json` constrains Gemini's decoding to emit syntactically valid JSON, directly satisfying the stem's requirement for structured output. This parameter enforces the output format at generation time, eliminating the malformed responses the developer currently receives from the Vertex AI Python SDK.
- ✗
Include few-shot examples of the desired JSON format in the system prompt.
Why it's wrong here
Few-shot examples bias the model toward a format but remain probabilistic guidance, so malformed output can still occur. The generation configuration's response schema or MIME type enforces valid JSON at decoding time. Few-shot prompting is the right choice for teaching nuanced style or labelling conventions.
- ✗
Switch to a smaller model to reduce complexity.
Why it's wrong here
Switching models does not constrain token sampling, so malformed JSON can still be emitted; the SDK's `response_mime_type` parameter is what forces syntactically valid JSON. Smaller models suit latency- or cost-sensitive workloads, but model size never guarantees schema conformance, making this the wrong lever for structured output enforcement.
Go deeper
Related to this question
About these practice questions
This Generative AI Leader question is part of Courseiva's 1,008-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This Generative AI Leader practice question is part of Courseiva's free Google Cloud certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the Generative AI Leader exam.