Structured output support with cached content

When trying to use Gemini to generate structured output with cachedContent I get the error:

CachedContent can not be used with GenerateContent request setting system_instruction, tools or tool_config
Proposed fix: move those values to CachedContent from GenerateContent request.

But I use tool or system instruction to instruct gemini in how to output structured output - it makes no sense to put it in the CachedContent because it is not re-used for any other flows.

What can I do here?

3 Likes

Hi @Daniel_Nygaard, I faced with same error for different setup.

  1. Created a cache,
  2. Instantiated a model,
  3. Call of model with generate_content method caused error
    InvalidArgument: 400 CachedContent can not be used with GenerateContent request setting system_instruction, tools or tool_config. Proposed fix: move those values to CachedContent from GenerateContent request.

BUT I don’t pass any additional args in generate_content (textual question only), as well as in model.

I’ve explored a code and API reference, but still have no idea what is going wrong.

Did you find a workaround?