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.

Implementation:Confident ai Deepeval Update LLM Span

From Leeroopedia
Revision as of 12:19, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Confident_ai_Deepeval_Update_LLM_Span.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Overview

Update LLM Span is the implementation function that enriches the current LLM-type span with model-specific metadata, including token usage counts, per-token costs, and prompt information. This function is designed to be called from within an @observe(type="llm") decorated function to attach economic and operational data to the span.

API Documentation

Function: update_llm_span

Source: deepeval/tracing/context.py:L120-150

Import:

from deepeval.tracing import update_llm_span

Signature:

update_llm_span(
    model=None,
    input_token_count=None,
    output_token_count=None,
    cost_per_input_token=None,
    cost_per_output_token=None,
    prompt=None,
)

Parameters

Parameter Type Description
model Optional[str] The name of the LLM model used (e.g., "gpt-4o", "claude-3-opus").
input_token_count Optional[float] The number of input (prompt) tokens consumed by this LLM call.
output_token_count Optional[float] The number of output (completion) tokens generated by this LLM call.
cost_per_input_token Optional[float] The monetary cost per input token (e.g., 0.0025 / 1000 for $2.50 per million tokens).
cost_per_output_token Optional[float] The monetary cost per output token (e.g., 0.01 / 1000 for $10.00 per million tokens).
prompt Optional The prompt template or content used for this LLM call.

Input / Output

  • Inputs: LLM usage data -- model name, token counts, per-token costs, and optional prompt content.
  • Outputs: The current LLM span is enriched with cost and token data, which is reflected in the Confident AI dashboard for cost tracking and performance analysis.

Usage Example

from deepeval.tracing import observe, update_llm_span

@observe(type="llm")
def call_llm(prompt: str) -> str:
    response = openai_client.chat.completions.create(...)
    update_llm_span(
        model="gpt-4o",
        input_token_count=response.usage.prompt_tokens,
        output_token_count=response.usage.completion_tokens,
        cost_per_input_token=0.0025 / 1000,
        cost_per_output_token=0.01 / 1000,
    )
    return response.choices[0].message.content

Relationships

Principle:Confident_ai_Deepeval_LLM_Span_Enrichment

Metadata

DeepEval Tracing Observability LLM_Evaluation 2026-02-14 09:00 GMT

Page Connections

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