Skip to main content
Applies to:


Summary

Issue: Code scorers in the Braintrust UI fail with ReferenceError: handler is not defined when the scorer function uses any name other than handler. Cause: The UI code scorer runtime requires the function to be named exactly handler. Resolution: Rename your scorer function to handler.

Resolution Steps

For TypeScript code scorers

Step 1: Rename function to handler

Update your scorer function name to handler:
function handler({
  input,
  output,
  expected,
  metadata,
}: {
  input: any;
  output: any;
  expected: any;
  metadata: Record<string, any>;
}): number | null {
  if (expected === null) return null;
  return output === expected ? 1 : 0;
}

For Python code scorers

Step 1: Rename function to handler

Update your scorer function name to handler:
def handler(input, output, expected, metadata):
    if expected is None:
        return None
    return 1 if output == expected else 0

Additional Notes

This naming requirement only applies to code scorers created in the UI. SDK-based scorers can use any function name.