Replies: 1 comment
|
Opened a PR with the implementation: langfuse/langfuse-python#2069 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem
The
@observedecorator is really convenient. Instead of managing observations manually with a context manageryou add one line above the function and keep its body clean.
But the traces it produces are hard to work with. Arguments are recorded as
{"args": [...], "kwargs": {...}}:{ "args": ["how do I return an item?", "en"], "kwargs": {"client": "<OpenAI object>"} }In practice this gets in the way:
args[0]andargs[1], and you have to open the code to understand what they are.answer("q", "en")andanswer(query="q", lang="en")produce different structures, which makes filtering traces and building datasets from them harder.The workaround is
capture_input=Falseplus a manualupdate_current_span(input=...), but then every function gets tracing code again and the decorator loses its point. The globalmaskdoesn't help either: it receives the already-built{"args", "kwargs"}and doesn't know the parameter names.Proposal
Add a
named_inputsflag. With it, the decorator binds arguments to the function signature viainspect.signature(func).bind(...)and records input with names:{"query": "how do I return an item?", "lang": "en", "client": "<OpenAI object>"}It can be enabled globally with
LANGFUSE_OBSERVE_DECORATOR_NAMED_INPUTS, the same waycapture_inputworks today. It's off by default, so nothing changes for existing users.A nice side effect: once inputs have names, the existing
maskcan drop parameters likeclientorsessionglobally. No separate filtering mechanism is needed.Details
selfandclsare excluded from input, as they are now.Open question: whether to record default values. I'd record only the arguments actually passed, so the trace reflects the real call.
Happy to open a PR.
English isn't my first language, so I used AI to help write this up. I've reviewed everything and stand behind the proposal.
All reactions