Mistake in example code for [Tracing FAQ]: run_id = id.traced_runs[0].id #2

Closed
opened 2026-02-21 17:16:56 -05:00 by yindo · 1 comment
Owner

Originally created by @linusschoch on GitHub (Sep 12, 2023).

In the documentation:
Tracing FAQ/How do I get the run id from a call, there is a mistake in the code (should be cb instead of id:

from langchain import chat_models, prompts, callbacks
chain = (
    prompts.ChatPromptTemplate.from_template("Say hi to {name}")
    | chat_models.ChatAnthropic()
)
with callbacks.collect_runs() as cb:
  result = chain.invoke({"name": "Clara"})
  run_id = id.traced_runs[0].id
print(run_id)

should be corrected to

from langchain import chat_models, prompts, callbacks
chain = (
    prompts.ChatPromptTemplate.from_template("Say hi to {name}")
    | chat_models.ChatAnthropic()
)
with callbacks.collect_runs() as cb:
  result = chain.invoke({"name": "Clara"})
  run_id = cb.traced_runs[0].id
print(run_id)
Originally created by @linusschoch on GitHub (Sep 12, 2023). In the documentation: [Tracing FAQ/How do I get the run id from a call](https://docs.smith.langchain.com/tracing/tracing-faq#how-do-i-get-the-run-id-from-a-call), there is a mistake in the code (should be `cb` instead of `id`: ```python from langchain import chat_models, prompts, callbacks chain = ( prompts.ChatPromptTemplate.from_template("Say hi to {name}") | chat_models.ChatAnthropic() ) with callbacks.collect_runs() as cb: result = chain.invoke({"name": "Clara"}) run_id = id.traced_runs[0].id print(run_id) ``` should be corrected to ```python from langchain import chat_models, prompts, callbacks chain = ( prompts.ChatPromptTemplate.from_template("Say hi to {name}") | chat_models.ChatAnthropic() ) with callbacks.collect_runs() as cb: result = chain.invoke({"name": "Clara"}) run_id = cb.traced_runs[0].id print(run_id) ```
yindo closed this issue 2026-02-21 17:16:56 -05:00
Author
Owner

@hinthornw commented on GitHub (Sep 12, 2023):

Great catch! Silly me

@hinthornw commented on GitHub (Sep 12, 2023): Great catch! Silly me
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langsmith-docs#2