Fix: Pass metadata from dataset to prompts in Python SDK init_function #1191
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.
Summary
Fixes a bug where metadata parameters from dataset records were not being passed through to prompt templates when running experiments via the Python SDK, even though they worked correctly in the UI.
Problem
When using
init_function()to create a task forEval(), dataset records containing metadata fields were not being propagated to the prompt templates. This caused mustache template variables like{{metadata.fieldName}}to render as empty strings instead of their actual values.Example of the issue:
Root Cause
The
init_function()wrapper was not extracting metadata from thehooksparameter that the evaluation framework provides when calling task functions. The framework passes aDictEvalHooksobject containing the metadata, butinit_function()was only forwarding the input data toinvoke().Solution
Modified
init_function()to:input,hooks) to match framework requirements for passing hookshooks.metadatawhen availableinvoke()call for proper template substitutionChanges
f(*args, **kwargs)tof(input, hooks=None)invoke()for both task and scorer modesTest Plan
Impact
This fix ensures that SDK users can properly use metadata parameters in their prompt templates, achieving feature parity with the UI. This is especially important for users who rely on metadata for dynamic prompt generation or context injection.
🤖 Generated with Claude Code