Skip to content

Commit 3e247c2

Browse files
AbhiPrasadclaude
andcommitted
docs(functions): clarify where invoke metadata reaches code functions
The invoke() docstring said top-level metadata is passed to the function as its metadata argument. That holds for prompts ({{metadata}}), but code functions receive it through the hooks, while the handler's metadata argument is read from input. Document this and show how to nest metadata in input. Mirrors braintrustdata/braintrust-sdk-python#1073. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 245d1f9 commit 3e247c2

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"braintrust": patch
3+
---
4+
5+
docs(functions): clarify where invoke metadata reaches code functions

‎js/src/functions/invoke.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ export interface InvokeFunctionArgs<
7878

7979
/**
8080
* Additional metadata to add to the span. This will be logged as the `metadata` field in the span.
81-
* It will also be available as the {{metadata}} field in the prompt and as the `metadata` argument
82-
* to the function.
81+
* It will also be available as the {{metadata}} field in the prompt. For code functions, it is passed
82+
* through the hooks (the handler's second argument in TypeScript, `hooks.metadata` in Python), not
83+
* as the handler's `metadata` argument, which is read from `input`. To fill the handler's `metadata`
84+
* argument, nest it in `input`, e.g. `invoke({ ..., input: { input: ..., metadata: { ... } } })`.
8385
*/
8486
metadata?: Record<string, unknown>;
8587
/**

0 commit comments

Comments
 (0)