googleapis / googleapis/python-genai

Feature request: support caching response_schema/structured-output config in CreateCachedContentConfig

Aperta
#2,959 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

@Venkaiahbabuneelam ci sta già lavorando.

Dal 11/9/2026.

priority: p3 type: feature request
Lingua principale
Python
Stelle
4k
Fork
1k
Merge medio
2g 12h
PR unite (30g)
41

Descrizione

`CreateCachedContentConfig` currently accepts `system_instruction`, `contents`, `tools`, and `tool_config`, but not `response_schema`/`response_mime_type`. For prompts with large structured-output schemas, this means the schema is resent at full price on every call even when `system_instruction` is cached.

The only current workaround is converting the schema into a single forced-choice `FunctionDeclaration`/`Tool` and baking that + `tool_config` into the cache instead — which we validated works (schema tokens do show up under `cached_content_token_count`), but it comes with real downsides vs. native `response_schema` support:

- Loses whatever constrained-decoding guarantee `response_schema` mode provides — function-calling isn't documented as giving the same schema-adherence guarantee.
- Introduces `MALFORMED_FUNCTION_CALL` as a new failure mode (see #1789) with no equivalent under `response_schema` mode.
- Requires a full generate_content config swap (can't mix `response_schema` with `tools`/`tool_config` in the same cached request per current API validation), so cache-hit vs. cache-miss calls need materially different request shapes.

Feature request: allow `response_schema`/`response_mime_type` to be part of the cached content directly, so structured-output prompts get the same caching benefit as system-instruction-heavy ones without the function-calling workaround.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.