ValueError
langsmith.exceptions.ValueError: Trace parent run not found
Stack trace
Traceback (most recent call last):
File "app.py", line 42, in <module>
run = client.runs.create(...)
File "/usr/local/lib/python3.9/site-packages/langsmith/client.py", line 120, in create
raise ValueError("Trace parent run not found")
ValueError: Trace parent run not found Why it happens
LangSmith requires a valid parent run ID to maintain trace continuity across runs. This error occurs when the parent run ID is missing, expired, or incorrectly passed, causing the SDK to fail linking the current run to its parent trace.
Detection
Monitor your run creation calls for ValueError exceptions and log the parent run ID being passed; missing or invalid IDs indicate this error before it crashes.
Causes & fixes
Parent run ID is not passed or is None when creating a new run
Ensure you explicitly pass a valid parent run ID string when creating or continuing a run in LangSmith.
Parent run ID has expired or was deleted from LangSmith backend
Fetch or create a fresh parent run ID before starting child runs to maintain valid trace linkage.
Incorrect environment or client configuration causing loss of trace context
Verify your LangSmith client initialization and environment variables to ensure trace context is preserved and propagated.
Code: broken vs fixed
from langsmith import LangSmithClient
client = LangSmithClient()
# Missing parent run ID causes error
run = client.runs.create(name="child-run") # ValueError: Trace parent run not found import os
from langsmith import LangSmithClient
os.environ["LANGSMITH_API_KEY"] = os.environ["LANGSMITH_API_KEY"]
client = LangSmithClient()
parent_run_id = "valid_parent_run_id"
run = client.runs.create(name="child-run", parent_run_id=parent_run_id) # Fixed: pass valid parent run ID
print(f"Run created with ID: {run.id}") Workaround
Catch the ValueError on run creation, then create a new root run without a parent ID as a fallback to continue execution without trace linkage.
Prevention
Implement centralized trace context management in your app to always propagate and validate parent run IDs before creating new runs, ensuring trace continuity.