Fix: Pass metadata from dataset to prompts in Python SDK init_function#1191
Closed
Alex Jean-Baptiste (justcodebruh) wants to merge 1 commit intomainfrom
Closed
Fix: Pass metadata from dataset to prompts in Python SDK init_function#1191Alex Jean-Baptiste (justcodebruh) wants to merge 1 commit intomainfrom
Alex Jean-Baptiste (justcodebruh) wants to merge 1 commit intomainfrom
Conversation
When running experiments via SDK, metadata from dataset records was not
being passed through to prompt templates. This fix modifies init_function()
to accept and extract metadata from the hooks parameter when called as a
task, and properly pass it to the invoke() call.
The function now:
- Accepts exactly 2 parameters (input, hooks) to match framework requirements
- Extracts metadata from hooks.metadata when present
- Passes metadata to invoke() for proper template substitution
- Maintains backward compatibility for both task and scorer modes
This ensures mustache template variables like {{metadata.fieldName}} are
correctly rendered with dataset metadata values during SDK experiments.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
| if len(args) > 0: | ||
| # Task. | ||
| return invoke(project_name=project_name, slug=slug, version=version, input=args[0]) | ||
| def f(input, hooks=None): |
Collaborator
There was a problem hiding this comment.
i'm not sure if input / hooks are the only possible args, but if other things were passed in e.g.f(foo=123) this will be backwards incompatible.
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If this PR is still relevant, please leave a comment, push an update, or remove the stale label. Thank you for your contributions! |
|
This pull request was closed because it has been inactive for 21 days (14 days of inactivity before being marked stale, plus 7 additional days). If this PR is still relevant, please feel free to reopen it. Thank you! |
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.
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