fix(evaluator): strip PEP 604 union return annotations before upload (#167)#169
Open
Josiah Coad (josiahcoad) wants to merge 1 commit into
Conversation
`evaluator upload` failed with a misleading "Code evaluator does not contain function with name perform_eval" when the Python entrypoint had a union return annotation (e.g. `-> dict | None`). The function IS present; the evaluator service's function finder just doesn't handle union return annotations. A plain annotation (`-> dict`) or no annotation uploads fine. Strip the return annotation from the def line before upload (it's irrelevant to execution), preserving params and any trailing comment. Adds unit tests. Fixes langchain-ai#167. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #167.
Problem
langsmith evaluator uploadfails with a misleading error when the Python entrypoint has a PEP 604 union return annotation (-> dict | None):The function is present. The evaluator service's function finder just doesn't handle union return annotations — a plain annotation (
-> dict) or no annotation uploads fine. Confirmed with three files identical except the annotation: no-annotation ✅,-> dict✅,-> dict | None❌.Fix
Strip the return-type annotation from the
defline of the extracted/renamed Python function before upload (it's irrelevant to execution), preserving the params and any trailing comment:This is a client-side mitigation; the underlying service-side function finder could also be made union-aware, but stripping the annotation is safe and unblocks users today.
Tests
TestStripPythonReturnAnnotation_*(union, plain, params+comment, no-annotation-unchanged).go test ./internal/cmd/passes;gofmt/go vetclean.-> dict | Noneevaluator (incl. a trailing comment) that previously returned HTTP 400 now uploads successfully with the patched binary.