Skip to content

pi_llm.utils.overflow

overflow

Context window overflow detection across providers.

Detects when an LLM response indicates the input exceeded the model's context window, covering 20+ provider-specific error patterns.

is_context_overflow(message, context_window=None)

Check if an assistant message represents a context overflow error.

Handles two cases: 1. Error-based overflow: Most providers return stop_reason "error" with a specific error message pattern. 2. Silent overflow: Some providers (e.g. z.ai) accept overflow silently. For these, check if usage.input exceeds the context window.