Skip to content

fix(core): honor custom aparse in aparse_result - #41894

Open
ccurme (ccurme) wants to merge 1 commit into
masterfrom
ccurme/core/honor-aparse-override
Open

ccurme (ccurme) wants to merge 1 commit into
masterfrom
ccurme/core/honor-aparse-override

Conversation

@ccurme

Copy link
Copy Markdown
Collaborator

Parsers that override aparse but inherit parse_result currently route ainvoke through synchronous parsing on a worker thread, which can put async clients on the wrong event loop. Use the native aparse in that case while preserving executor dispatch for custom parse_result implementations, including inherited overrides, generation metadata, and partial behavior.

Thanks to Andreas Germann, AXA, for reporting this.

Release note

BaseOutputParser.aparse_result and ainvoke now honor overridden aparse methods when parse_result is not overridden, keeping native async parsing on the caller’s event loop.

AI-assisted contribution using Robin.

Made by Robin (production) · view thread · openai:gpt-6.1-sol (xhigh)

Use native async parsing when generation parsing is unchanged, while preserving custom parse_result dispatch.

Co-authored-by: Robin <open-swe@users.noreply.github.com>
@codspeed

codspeed Bot commented Nov 16, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 15 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing ccurme/core/honor-aparse-override (ca71817) with master (ccf1624)2

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on master (80655a1) during the generation of this report, so ccf1624 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@ccurme
ccurme (ccurme) marked this pull request as ready for review November 16, 2026 20:25

@robin-agent robin-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robin Review found 1 potential issue.

Open in Robin

Comment on lines +303 to +307
if (
type(self).aparse is not BaseOutputParser.aparse
and type(self).parse_result is BaseOutputParser.parse_result
):
return await self.aparse(result[0].text)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Custom aparse delegating to aparse_result now recurses forever

Some subclasses override aparse only to forward to aparse_result, e.g. async def aparse(self, text): return await self.aparse_result([Generation(text=text)]), and inherit parse_result. Before this change that worked, because aparse_result called parse_result → parse in an executor. Now aparse_result sees the overridden aparse and calls it, which calls aparse_result again. The result is RecursionError on ainvoke/aparse.

This is a less common pattern, but it is a silent behavior change for public subclasses. Please call it out in the release note, or add a test documenting that it isn't supported.

(Refers to lines 303-307)


Your feedback helps Robin learn. React with 👍 or 👎 to tell us if this review comment was useful.

This branch has not been deployed

No deployments
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