Skip to content

fix(pydantic-ai): set output.value for plain text responses#2944

Open
ritiztambi wants to merge 1 commit intoArize-ai:mainfrom
ritiztambi:fix/pydantic-ai-output-value-plain-text
Open

fix(pydantic-ai): set output.value for plain text responses#2944
ritiztambi wants to merge 1 commit intoArize-ai:mainfrom
ritiztambi:fix/pydantic-ai-output-value-plain-text

Conversation

@ritiztambi
Copy link
Copy Markdown

Fixes #2943

Summary

  • When a PydanticAI agent uses the default output_type=str, the LLM responds with plain text (no final_result tool call). output.value was never set in this case, causing downstream consumers (e.g. Langfuse) to show null output.
  • Captures the first assistant text part as output_value in _extract_from_gen_ai_messages(), mirroring how input.value is derived from the last user text part
  • If a final_result tool call is also present, it still overwrites output_value, preserving existing behavior for structured output agents

Change

One-line addition in semantic_conventions.py — after yielding llm.output_messages.*.message.content for a text part, also set output_value if not already set.

When a PydanticAI agent uses the default `output_type=str`, the LLM
responds with a plain text message (no `final_result` tool call).
The `_extract_from_gen_ai_messages()` function was only setting
`output.value` when a `final_result` tool call was present, leaving
it unset for plain text responses.

This caused downstream consumers (e.g. Langfuse) that rely on
`output.value` to show null output for the most common PydanticAI
usage pattern.

The fix captures the first assistant text part as `output_value`,
mirroring how `input.value` is derived from the last user text part.
If a `final_result` tool call is also present, it still takes
precedence (overwrites `output_value`), preserving existing behavior
for structured output agents.
@ritiztambi ritiztambi requested a review from a team as a code owner April 1, 2026 17:47
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@ritiztambi
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Apr 1, 2026
@ritiztambi
Copy link
Copy Markdown
Author

recheck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

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

1 participant