Repository navigation
fix(core): honor custom aparse in aparse_result - #41894
ccurme (ccurme) wants to merge 1 commit into
Conversation
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>
Merging this PR will not alter performance
Comparing Footnotes
|
| if ( | ||
| type(self).aparse is not BaseOutputParser.aparse | ||
| and type(self).parse_result is BaseOutputParser.parse_result | ||
| ): | ||
| return await self.aparse(result[0].text) |
There was a problem hiding this comment.
🔵 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.
Parsers that override
aparsebut inheritparse_resultcurrently routeainvokethrough synchronous parsing on a worker thread, which can put async clients on the wrong event loop. Use the nativeaparsein that case while preserving executor dispatch for customparse_resultimplementations, including inherited overrides, generation metadata, andpartialbehavior.Thanks to Andreas Germann, AXA, for reporting this.
Release note
BaseOutputParser.aparse_resultandainvokenow honor overriddenaparsemethods whenparse_resultis 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)