Skip to content

fix(evaluator): strip PEP 604 union return annotations before upload (#167)#169

Open
Josiah Coad (josiahcoad) wants to merge 1 commit into
langchain-ai:mainfrom
josiahcoad:fix/evaluator-upload-union-return-annotation
Open

fix(evaluator): strip PEP 604 union return annotations before upload (#167)#169
Josiah Coad (josiahcoad) wants to merge 1 commit into
langchain-ai:mainfrom
josiahcoad:fix/evaluator-upload-union-return-annotation

Conversation

@josiahcoad

Copy link
Copy Markdown

Fixes #167.

Problem

langsmith evaluator upload fails with a misleading error when the Python entrypoint has a PEP 604 union return annotation (-> dict | None):

HTTP 400: Code evaluator does not contain function with name perform_eval

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 def line of the extracted/renamed Python function before upload (it's irrelevant to execution), preserving the params and any trailing comment:

def perform_eval(run) -> dict | None:        ->  def perform_eval(run):
def perform_eval(run, ex) -> dict | None:  # x ->  def perform_eval(run, ex):  # x
def perform_eval(run) -> dict:               ->  def perform_eval(run):
def perform_eval(run):                       ->  (unchanged)

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

  • Added TestStripPythonReturnAnnotation_* (union, plain, params+comment, no-annotation-unchanged).
  • go test ./internal/cmd/ passes; gofmt/go vet clean.
  • Verified end-to-end against the live API: a -> dict | None evaluator (incl. a trailing comment) that previously returned HTTP 400 now uploads successfully with the patched binary.

`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>
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.

evaluator upload: misleading "function not found" when entrypoint has a PEP 604 union return annotation (-> dict | None)

1 participant