Skip to content

Python HITL docs/samples: use AgentResponse.value instead of model_validate_json for structured outputs #4396

@pamelafox

Description

@pamelafox

Summary

The HITL documentation page and the guessing_game_with_human_input.py sample use model_validate_json() to parse structured agent output inside workflow executors:

text = result.agent_response.text
last_guess = GuessOutput.model_validate_json(text).guess

Since the agent is configured with response_format=GuessOutput, the AgentResponse object already has a .value property that returns the parsed Pydantic model directly:

last_guess = result.agent_response.value.guess

Using .value is more idiomatic and avoids redundant parsing. It also better communicates that structured outputs are a first-class feature — the framework already handles the JSON parsing when response_format is set.

Affected files

Context

It's possible model_validate_json was used because .value wasn't available on AgentResponse when the sample was originally written, or because .value support inside AgentExecutorResponse.agent_response was added later. Either way, .value is available today and would be the cleaner approach.

This also applies to other workflow samples that use model_validate_json with structured response_format agents (e.g. agents_with_approval_requests.py, checkpoint samples, etc.).

Metadata

Metadata

Assignees

Labels

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions