Skip to content

Wolo/output validation llmagent#1048

Draft
wolo-lab wants to merge 2 commits into
wolo/output-validation-cleanupfrom
wolo/output-validation-llmagent
Draft

Wolo/output validation llmagent#1048
wolo-lab wants to merge 2 commits into
wolo/output-validation-cleanupfrom
wolo/output-validation-llmagent

Conversation

@wolo-lab

Copy link
Copy Markdown
Contributor

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

  • Closes: #issue_number
  • Related: #issue_number

2. Or, if no issue exists, describe the change:

If applicable, please follow the issue templates to provide as much detail as
possible.

Problem:
A clear and concise description of what the problem is.

Solution:
A clear and concise description of what you want to happen and why you choose
this solution.

Testing Plan

Please describe the tests that you ran to verify your changes. This is required
for all PRs that are not small documentation or typo fixes.

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Please include a summary of passed go test results.

Manual End-to-End (E2E) Tests:

Please provide instructions on how to manually test your changes, including any
necessary setup or configuration. Please provide logs or screenshots to help
reviewers better understand the fix.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

Add any other context or screenshots about the feature request here.

wolo-lab added 2 commits June 16, 2026 15:40
Make the scheduler the single authoritative point for output
validation. FunctionNode.wrappedFn and ToolNode.runTool no longer
validate the output against their schema inline; the schema still
flows through BaseNode so the scheduler enforces it on every yielded
event with non-nil output. This removes duplicate validation and the
risk of drift as the scheduler logic evolves (symmetric to the input
validation cleanup).

The FunctionTool {"result": X} unwrap fallback is not lost: it moves
to a ToolNode.ValidateOutput override, the correct home for that
tool-specific convention. The override tries standard validation
first, then unwraps a "result" key and validates the unwrapped value,
and finally re-runs standard validation so callers see the original
schema-mismatch error rather than a fallback artifact. nil schema is
a passthrough.

Tests that previously asserted on inline behavior are updated:
- FunctionNode: the inline ValidationError table case is replaced by
  TestFunctionNode_ValidateOutput, which asserts Run passes the output
  through unchanged and ValidateOutput surfaces the schema mismatch.
- ToolNode: TestToolNode_Run now asserts the raw FunctionTool map
  output from Run (no inline unwrap); the new
  TestToolNode_ValidateOutput covers the four override cases
  (direct-valid passthrough, {"result": X} unwrap, both-fail original
  error, nil-schema passthrough).

BUG=516382303
BUG=516382092
…tate

Complete the long-standing TODO in maybeSaveOutputToState: when
LlmAgent.OutputSchema is set, the final model text is JSON-parsed and
validated against the schema, and the validated object is written to
state[OutputKey] (and Event.Output) instead of the raw text. With no
schema, the raw text is saved as before. Invalid JSON or output that
does not match the schema causes the state write to be skipped rather
than persisting malformed output.

Uses the existing utils.ValidateOutputSchema helper (already used by
agenttool) for the genai.Schema parse-and-validate, keeping the
behavior consistent across the codebase. Brings adk-go to parity with
adk-python's __maybe_save_output_to_state, where state[output_key]
holds the validated object.

Behavior change: users who set both OutputKey and OutputSchema
previously got the raw model text in state; they now get the parsed
and validated object. Users who set only OutputKey (the common case)
see no change. This is documented as a behavior change; the prior
behavior was an explicitly unfinished TODO and had no test coverage
for the schema-present path.

Tests: llmagent_saveoutput_test.go now covers the three schema paths
(valid JSON matching schema saves the parsed object, invalid JSON
skips the write, valid JSON not matching the schema skips the write).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant