fix: return ContextLengthExceeded when prompt exceeds effective KV cache size (#7815)

Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
Douwe Osinga
2026-03-11 15:13:11 -04:00
committed by GitHub
parent f2de8b5ccc
commit f462d73347
@@ -226,6 +226,13 @@ pub(super) fn validate_and_compute_context(
)));
}
}
if prompt_token_count >= effective_ctx {
return Err(ProviderError::ContextLengthExceeded(format!(
"Prompt ({} tokens) exceeds context limit ({} tokens). \
Try reducing conversation length.",
prompt_token_count, effective_ctx,
)));
}
Ok((prompt_token_count, effective_ctx))
}