Repository navigation
Commit 47f1653
docs(functions): clarify where invoke metadata reaches code functions (#2731)
> 🤖 **This text was AI-generated.**
The `invoke()` docstring said top-level `metadata` is passed to the
function as its `metadata` argument. That is true for prompts
(`{{metadata}}`), but not for code functions. The runtime sends
top-level `metadata` as hook data, and a Python handler's `metadata`
argument is only filled from `input`:
```typescript
await invoke({ ..., input: { input: "x" }, metadata: { marker: "top" } });
```
```python
def handler(input=None, metadata=None, hooks=None):
metadata # None
hooks.metadata # {"marker": "top"}
```
A customer's scorer therefore saw an empty `metadata` argument on every
row.
The docstring now explains that code functions receive top-level
metadata through the hooks (the second handler argument in TypeScript,
`hooks.metadata` in Python), and shows how to fill the `metadata`
argument by nesting it in `input`:
```typescript
await invoke({ ..., input: { input: "x", metadata: { marker: "nested" } } });
```
The runtime behaviour is unchanged. The same wrong sentence also appears
in the generated `js/src/generated_plain_types.ts`. It comes from the
backend typespec (`typespecs/src/functions.ts`) and needs fixing there,
then regenerating.
Mirrors braintrustdata/braintrust-sdk-python#1073.
Refs: SDK-791
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 245d1f9 commit 47f1653
2 files changed
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
83 | 85 | | |
84 | 86 | | |
85 | 87 | | |
| |||
0 commit comments