Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Wandb Weave LLM Call Interception

From Leeroopedia
Knowledge Sources
Domains Observability, LLM_Operations
Last Updated 2026-02-14 00:00 GMT

Overview

A transparent interception pattern that captures LLM provider API calls and their streaming responses without modifying user code.

Description

LLM Call Interception uses the SymbolPatcher mechanism to replace provider SDK methods with traced wrappers. These wrappers delegate to the original method while capturing inputs, outputs, timing, and token usage. For streaming responses, an accumulator function merges incremental chunks into a complete response.

Usage

This principle operates transparently after patching is enabled. Users make normal LLM API calls (e.g., openai.chat.completions.create()) and the tracing happens automatically in the background.

Theoretical Basis

The interception uses a proxy wrapper pattern:

  1. Symbol Resolution: SymbolPatcher resolves the target method on the provider SDK (e.g., openai.resources.chat.completions.Completions.create).
  2. Replacement: The original method is saved and replaced with a weave.op-wrapped version.
  3. Transparent Delegation: The wrapper calls the original method, passing all arguments through.
  4. Streaming Accumulation: For streaming responses, an accumulator function merges ChatCompletionChunk objects into a complete ChatCompletion.
  5. Usage Extraction: Token counts and cost information are extracted from the response and included in the call summary.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment