Skip to content

Does Bedrock include outputConfig in its prompt caching key?

0

Hi there. When using Bedrock's Converse API with both cachePoint in the system prompt and outputConfig for structured output, it looks like only changing the schema between requests causes a prompt caching miss. I could not see this being documented anywhere. I found this to be an unexpected interaction between prompt caching and structured output that should either be documented or fixed.

Ruby illustration below:

require "aws-sdk-bedrockruntime"
require "json"
require "faker"

client = Aws::BedrockRuntime::Client.new(region: "us-west-2")

TEXT = Array.new(60) { Faker::Lorem.paragraph(sentence_count: 5) }.join("\n\n")

SYSTEM_PROMPT = <<~PROMPT
Summarize the text below:

<text>
#{TEXT}
</text>
PROMPT

SCHEMA_A = JSON.generate({
type: "object",
properties: { summary: { type: "string" }, key_points: { type: "array", items: { type: "string" } } },
required: ["summary", "key_points"],
additionalProperties: false
})

SCHEMA_B = JSON.generate({
type: "object",
properties: { topic: { type: "string" } },
required: ["topic"],
additionalProperties: false
})

def call(client, label, schema)
resp = client.converse(
    model_id: "us.anthropic.claude-sonnet-4-6",
    system: [
    { text: SYSTEM_PROMPT },
    { cache_point: { type: "default" } }
    ],
    messages: [{ role: "user", content: [{ text: "Summarize this text." }] }],
    inference_config: { temperature: 0 },
    output_config: {
    text_format: {
        type: "json_schema",
        structure: {
        json_schema: { schema: schema, name: label }
        }
    }
    }
)
u = resp.usage
puts "#{label}: input=#{u.input_tokens} cached_hit=#{u.cache_read_input_tokens}
cache_created=#{u.cache_write_input_tokens}"
end

puts "\n1. Warm up cache with Schema A"
call(client, "schema_a", SCHEMA_A)

puts "2. Same schema — expect a cache HIT"
call(client, "schema_a", SCHEMA_A)

puts "3. Different schema — expect a cache HIT but it is MISS"
call(client, "schema_b", SCHEMA_B)

puts "4. Back to Schema A — expect a cache HIT"
call(client, "schema_a", SCHEMA_A)
2 Answers
3

Your observation is spot on. While not explicitly detailed in the docs, it’s a known behavior in managed LLM environments: outputConfig (and specifically the JSON schema) is treated as part of the model's instruction state. Since the schema dictates how the model must structure its response, it is bundled into the cache key. Consequently, even if your system prompt remains identical, a change in the schema results in a different hash and a cache miss. To get a hit, the entire request configuration up to (and including) the cache_point must remain static.

EXPERT
answered a month ago
2

Based on the available documentation, I cannot find explicit information about whether outputConfig is included in Bedrock's prompt caching key. The documentation describes outputConfig as an optional parameter that controls the output configuration for a model response in calls to Converse or ConverseStream, and it includes a textFormat property for structured output parameters. However, the interaction between outputConfig (specifically JSON schema definitions) and prompt caching is not documented in the sources provided.

Your observation that changing the JSON schema in outputConfig causes a prompt cache miss is an important finding. This suggests that the schema definition may indeed be part of the caching key, even though the cached content (the system prompt with cache point) remains unchanged. This behavior would mean that different structured output schemas are treated as distinct requests for caching purposes, which could have significant implications for cache efficiency when using structured outputs with varying schemas.

This appears to be an undocumented aspect of how prompt caching interacts with structured outputs. Given that this behavior affects cache hit rates and could impact both performance and costs, it would be valuable to have this interaction explicitly documented or clarified in the official documentation.
Sources
OutputConfig - Amazon Bedrock
[Class: Aws::BedrockRuntime::Types::OutputConfig

— AWS SDK for Ruby V3](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/BedrockRuntime/Types/OutputConfig.html)  

Converse - Amazon Bedrock

answered a month ago
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.