Skip to content

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

Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi/sdk-791-functions-top-level-invocation-metadata-does-not-populate
Nov 5, 2026
Merged

Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi/sdk-791-functions-top-level-invocation-metadata-does-not-populate

Conversation

@AbhiPrasad

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) commented Nov 5, 2026 •

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:

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 (hooks.metadata in Python, the second handler argument in TypeScript), and shows how to fill the metadata argument by nesting it in input:

invoke(..., input={"input": "x", "metadata": {"marker": "nested"}})

The runtime behaviour is unchanged. The same wrong sentence also appears in the generated _generated_types.py. It comes from the backend typespec (typespecs/src/functions.ts) and needs fixing there, then regenerating.

Refs: https://linear.app/braintrustdata/issue/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`:

```python
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 (`hooks.metadata` in Python, the second handler argument in
TypeScript), and shows how to fill the `metadata` argument by nesting it in
`input`:

```python
invoke(..., input={"input": "x", "metadata": {"marker": "nested"}})
```

The runtime behaviour is unchanged. The same wrong sentence also appears in
the generated `_generated_types.py`. It comes from the backend typespec
(`typespecs/src/functions.ts`) and needs fixing there, then regenerating.

Refs: SDK-791
@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:24:51.075839Z 93fbd30 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.

Abhijeet Prasad (AbhiPrasad) added a commit to braintrustdata/braintrust-sdk-javascript that referenced this pull request Nov 5, 2026
> 🤖 **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>
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit 426567c into main Nov 5, 2026
98 checks passed
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) deleted the abhi/sdk-791-functions-top-level-invocation-metadata-does-not-populate branch November 5, 2026 16:46
Abhijeet Prasad (AbhiPrasad) added a commit to braintrustdata/braintrust-sdk-javascript that referenced this pull request Nov 5, 2026
…#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>
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