adk-model-and-output-contracts
Skill9 starsChanged 18 days agoMITView on GitHub
Design, harden or review what a Python Google ADK agent asks the model to emit and which model and settings produce it: output_schema contracts and their validation, repair loops, output_schema together with tools, Gemini model selection and lifecycle, thinking and sampling settings, and model failover. Use for structured output that arrives as prose, fenced JSON or invalid data, response-schema design, choosing or escalating a Gemini model, retrying the model's own 429 or quota errors, or FallbackModel decisions. Do not activate for measuring quality on a labelled set (adk-agent-evaluation), SQL wire schemas (adk-sql-agent-engineering), prompt wording (adk-agent-instructions), tool parameter schemas (adk-tool-interface-design), hosting-level latency (optimise-adk-on-google-cloud), budget and degradation policy (adk-operational-guardrails), tool API retries (safe-api-tool-calls) or a release's model migration (adk-release-engineering).
In this repository25 other files it gives its agents.
- adk-agent-evaluationSkill
- adk-agent-instructionsSkill
- adk-agent-interoperabilitySkill
- adk-agent-observabilitySkill
- adk-agent-securitySkill
- adk-discoverySkill
- adk-engineerSkill
- adk-fastapi-backendSkill
- adk-frontend-integrationSkill
- adk-governance-packSkill
- adk-memory-architectureSkill
- adk-operational-guardrailsSkill
- adk-portability-planningSkill
- adk-presenterSkill
- adk-release-engineeringSkill
- adk-sql-agent-engineeringSkill
- adk-system-designerSkill
- adk-tool-auth-and-secretsSkill
- adk-tool-interface-designSkill
- adk-workflow-designSkill
- deploy-adk-on-google-cloudSkill
- optimise-adk-on-google-cloudSkill
- practice-profileSkill
- protect-adk-sensitive-dataSkill
- safe-api-tool-callsSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 37
Run the two helpers with an available Python 3.11+ interpreter (interpreters) after resolving SKILL_DIR to this skill's directory.
- Very specific: line 62
Put the schema on LlmAgent.output_schema and the key on output_key.
- Distinctive: line 71
Read validation. Three checks are observable without a live model:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
ADK model and output contracts
Decide what the model is asked to emit, which model and settings produce it, and how code proves it. Deliver the smallest change to an existing agent or a review with observable findings. Keep the model deciding and code copying identifiers; keep the schema minimal; keep thinking on; keep every claim tied to the pinned ADK version.
Inspect before choosing a mode
- Record the pinned
google-adkandgoogle-genaiversions from the manifest and lockfile. Most behaviour below is for 2.8.0; compatibility lists what changed in 2.6 to 2.11. Keep pins unchanged unless a version decision is requested. - Find every model reference: string literals,
model=arguments,Gemini(...),LiteLlm(...),FallbackModel(...),-latestaliases and the agent default (LlmAgent.DEFAULT_MODELisgemini-3.5-flashin 2.8.0). - Find
generate_content_config,planner,output_schema,output_key,modeandtoolson eachLlmAgent. Note which agents combineoutput_schemawithtools. - Identify the backend:
GOOGLE_GENAI_USE_ENTERPRISE(the deprecated spellingGOOGLE_GENAI_USE_VERTEXAIstill works with aDeprecationWarningin 2.8.0), project and location, or an API key. The backend decides how a schema is enforced (output schema and tools). In an Agents CLI project (agents-cli-manifest.yamlpresent) the scaffold writesGOOGLE_GENAI_USE_ENTERPRISE=trueandgemini-3.8-flash; consult the installedgoogle-agents-cli-adk-codeskill (references/adk-python.md) for those conventions; if it is not installed, adk-engineer explains how to get it. - Run the two helpers with an available Python 3.11+ interpreter (interpreters) after resolving
SKILL_DIRto this skill's directory. They read source only; they never import the project or call a provider.
python "$SKILL_DIR/scripts/audit_model_config.py" --project .
python -c 'from app.schemas import Decision; import json; print(json.dumps(Decision.model_json_schema()))' > .adk-evidence/decision.json
python "$SKILL_DIR/scripts/check_response_schema.py" --schema .adk-evidence/decision.json --pydantic-jsonThe audit reports model strings with a lifecycle status from a dated table (assets/model-lifecycle-2026-10-01.json, refresh it before trusting it), rejected generate_content_config fields, thinking and temperature mismatches, planner precedence and schema-with-tools combinations. The schema checker reports keywords outside the Gemini documented subset, depth, property and enum counts, nullable styles and unresolved $refs. Both direct inspection; neither certifies provider acceptance. Exit 1 from the audit means a partial scan; exit 1 from the checker means unsupported keywords.
Choose the relevant mode
| Mode | Read | Produce |
| (a) Design an output contract | output contracts | A minimal schema in the documented subset with a nullable refusal path; the model decides, code copies identifiers |
| (b) Harden an existing contract (fences, prose instead of JSON, nulls, validation failures) | validation and repair, then output schema and tools when tools are present | The 2.8.0 save path understood, a bounded repair loop with an explicit failure outcome, finish reasons handled |
| (c) Choose or escalate a model | model selection | Current model IDs with dates, a measured comparison handed to adk-agent-evaluation's two-stage escalation |
| (d) Configure thinking and sampling | reasoning and sampling | thinking_level on Gemini 3, temperature left at 1.0, one place for thinking config, output limit covering thought tokens |
| (e) Add failover | failover and providers | FallbackModel from 2.9.0 or an application-level alternative on 2.8.0, global endpoint decision, LiteLLM caveats |
| (f) Review | All of the above as needed, plus validation | Findings with file and line, each tied to a source-verified behaviour, with the test that would prove the fix |
Modes compose. A model escalation that changes thinking defaults is (c) plus (d); a schema that stops validating after a model change is (b) plus (c).
Implement the contract
- Put the schema on
LlmAgent.output_schemaand the key onoutput_key.generate_content_configrejectstools,system_instructionandresponse_schemawith aValueErrorin 2.8.0, and a base URL inhttp_options. Keep thinking in one place: aBuiltInPlanner.thinking_configoverwritesgenerate_content_config.thinking_configand ADK warns at construction. - Keep the schema small enough to describe in one sentence per field. Ask for a decision, a short reason and identifiers the model saw; copy everything else from trusted data in code. Give refusal a first-class shape (a status enum plus nullable payload fields) so a valid "no" survives
exclude_none=True. - With tools present, decide on which backend the agent runs. On Vertex (enterprise mode) with a Gemini model, 2.8.0 sets the native response schema alongside tools; on the API-key backend it adds a
set_model_responsetool and an instruction, which is best-effort. A formatting sub-agent without tools is the dependable alternative. - Treat a validation failure as a product outcome. In 2.8.0,
validate_schemastrips a whole-payload code fence, then raises on invalid JSON or a Pydantic error; the exception leaves the agent run. Catch it at a boundary you own, retry within an attempt budget with the error as feedback, then emit the explicit failure shape. Record which attempt succeeded. - On Gemini 3 use
thinking_level, leave temperature at its default of 1.0, and sizemax_output_tokensfor thinking plus output. Prefer minimal or low thinking for classification and lookup; keep thinking on for decisions. Reasoning happens before the constrained answer, in the same call or a prior one. - Choose models by measured quality on the project's development set, then cost, then lifecycle. A cheaper model is a hypothesis until the four metrics in validation say otherwise.
Validate and finish
Read validation. Three checks are observable without a live model:
- A scripted-model test in which the model returns invalid JSON, fenced JSON and schema-valid wrong data; it proves the attempt budget, the explicit failure outcome and that wrong-valid-schema is counted separately from invalid output.
- A request-capture test (a
before_model_callbackor a transport double) showing which config field carried the schema (response_schemaplusresponse_mime_typein 2.8.0) and whether the tools list containsset_model_response, so the native or workaround path is known rather than assumed. - A development-set comparison through adk-agent-evaluation reporting schema validity, answer accuracy, executable or actionable accuracy and wrong-valid-schema separately, with finish reason and thought tokens recorded per run.
<!-- shared:consequential-operations-brief -->Inspection is read-only, and code generation authorises no deployment, paid call or live test. Before any consequential operation (an API, billing or quota change, a billable resource, a secret, IAM, a data migration, a deployment, a deletion, or a paid or destructive test), read consequential operations, present the exact scope and limits, obtain explicit approval and end the turn to wait for it. Cleanup is a separate confirmed operation on resources this workflow created.
<!-- /shared:consequential-operations-brief -->Live model calls, model switches in production and new quota or endpoint settings are among them: present model, backend, project, location, request count and cost ceiling. Keep configuration examples synthetic.
Report what was inspected, what the helpers found, which tests ran and what remains unverified. A scripted-model test is local (mocked). Record every URL with its page date; model availability and defaults change faster than this skill.
<!-- shared:evidence-labels-brief -->Label each result with its tier (offline, local, live or release) and
outcome (pass, fail, blocked or not run) as
evidence labels defines them;
earlier, vendor and documentation-only results are historical,
vendor-measured or guidance, never this session's evidence.
<!-- /shared:evidence-labels-brief -->Independent community project; not affiliated with or endorsed by Google.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

