Skip to content

[bug] pydantic-ai: output.value not set for plain text (str) agent responses #2943

@ritiztambi

Description

@ritiztambi

Description

The OpenInferenceSpanProcessor for PydanticAI does not set output.value when the agent returns plain text (output_type=str, the default). It only sets output.value when a final_result tool call is present (structured output mode).

This causes downstream consumers that rely on output.value (e.g. Langfuse OTLP ingestion) to show null for the output field on LLM generation spans.

Steps to reproduce

  1. Create a PydanticAI agent with default output_type=str
  2. Instrument with OpenInferenceSpanProcessor
  3. Run the agent — LLM responds with plain assistant text
  4. Inspect the exported span attributes

Expected: output.value is set to the assistant's text response
Actual: output.value is missing; only llm.output_messages.0.message.content is set

Root cause

In semantic_conventions.py, _extract_from_gen_ai_messages() processes gen_ai.output.messages:

  • For text parts (line ~824): yields llm.output_messages.*.message.content but does NOT set output_value
  • For tool call parts with name final_result (line ~842): sets output_value

So output.value is only emitted for structured output agents. Plain text agents (the default) get no output.value.

Note that input.value IS correctly set from the last user text part in gen_ai.input.messages — the output side is just missing the equivalent logic.

Environment

  • openinference-instrumentation-pydantic-ai==0.1.12
  • pydantic-ai==1.70.0

Metadata

Metadata

Assignees

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions