Skip to content

feat(observe): add named_inputs option to record input by parameter name - #2069

Open
rusih100 wants to merge 2 commits into
langfuse:mainfrom
rusih100:feat/observe-named-inputs
Open

rusih100 wants to merge 2 commits into
langfuse:mainfrom
rusih100:feat/observe-named-inputs

Conversation

@rusih100

@rusih100 rusih100 commented Oct 28, 2026 •

Copy link
Copy Markdown

What does this PR do?

Adds an opt-in named_inputs flag to @observe. When enabled, input is recorded
by parameter name instead of {"args": [...], "kwargs": {...}}.

@observe(named_inputs=True)
def answer(query: str, lang: str): ...

answer("how do I return an item?", "en")
# Before: {"args": ["how do I return an item?", "en"], "kwargs": {}}
# After:  {"query": "how do I return an item?", "lang": "en"}

answer_before uses the default, answer_after uses named_inputs=True:

image
Script used for the screenshot
from langfuse import get_client, observe


@observe(name="answer_before")
def answer_before(query: str, lang: str) -> str:
    return query


@observe(name="answer_after", named_inputs=True)
def answer_after(query: str, lang: str) -> str:
    return query


answer_before("how do I return an item?", "en")
answer_after("how do I return an item?", "en")

get_client().flush()
  • Binds arguments with inspect.signature; only passed arguments are recorded, defaults are not.
  • self / cls are excluded.
  • Falls back to the current format if binding fails.
  • Default behavior is unchanged.

Discussion: https://github.com/orgs/langfuse/discussions/19377

Type of change

  • New feature

Verification

uv run --frozen ruff check .
uv run --frozen mypy langfuse --no-error-summary
uv run --frozen pytest -n auto --dist worksteal tests/unit

Checklist

  • I self-reviewed the diff using code_review.md.
  • I added or updated tests for behavior changes.

RetriggerView in GreptileConfidence Score: 4/5

The PR appears safe to merge, with a non-blocking issue where a later cls parameter causes a real input to disappear from traces.

Summary

Adds opt-in named_inputs to @observe.

  • Decorated calls can record inputs under their parameter names.

Reviews (1) · Last reviewed commit: "feat(observe): add named_inputs option t..." · Reviewed by Greptile

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Comment thread langfuse/_client/observe.py Outdated

This branch has not been deployed

No deployments
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.

1 participant