LangSmith is LangChain’s observability platform: it captures a complete trace of every run, every language model call, every tool invocation and every token, and stores them for inspection. Tracing turns on with environment variables, with no code changes required, and every LangChain run is then automatically traced. Open the project in the LangSmith dashboard and read the timeline of a real run before you change anything about the agent.
What you need
- Python with langchain and langsmith installed and an API key
- A LangChain agent that already runs
- A LangSmith account and API key, and a project name
Step 1: Turn on tracing with environment variables
Set the tracing flag, the LangSmith API key and the project name as environment variables, then run the agent once. No code changes are needed: every run is automatically traced once the variables are set.
Step 2: Open the run in the LangSmith dashboard
Open the project in the LangSmith dashboard and find the run. Read the timeline step by step: each language model call, tool invocation, input, output, latency and token count.
Step 3: Pick the worst run and fix one thing
Find a run that went wrong, click into the step where it went wrong, and read the exact prompt that was sent and the exact completion that came back. Fix that one step, re-run, and confirm the new trace shows the fix.
Worked example: synthetic trace review
The table below is a synthetic example. It shows the expected result of tracing; no run was traced.
| Run | Steps traced | Problem found? |
|---|---|---|
| Run 1 | All steps | No |
| Run 2 | All steps | Yes – wrong tool |
| Run 3 | All steps | No |
Expected result (UNTESTED). all three runs are fully traced, the wrong tool call in run 2 is visible in the timeline, and the fix is confirmed in a later trace. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- Tracing needs the API key and project set before the run; a run that happened before tracing was on is not recorded.
- Traces include the exact prompts and completions, so treat them as sensitive and limit who can open the project.
- A trace shows what the agent really did, so read it before patching the code; the code only describes what the agent was permitted to do.
