Skip to content

docs(functions): clarify where invoke metadata reaches code functions - #2731

Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
fix-docstring-sdk-pr-1073-fd521c93
Nov 5, 2026
Merged

Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
fix-docstring-sdk-pr-1073-fd521c93

Conversation

@AbhiPrasad

Copy link
Copy Markdown
Member

🤖 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:

await invoke({ ..., input: { input: "x" }, metadata: { marker: "top" } });
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:

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

> 🤖 **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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T15:28:40.059555Z d265678 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit 47f1653 into main Nov 5, 2026
61 checks passed
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) deleted the fix-docstring-sdk-pr-1073-fd521c93 branch November 5, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants