Context
You want to exclude entire traces from your LangSmith query results when those traces contain a node with a specific name. You may have tried using tree_filter with neq(name, "node_name"), but this approach doesn't work as expected because it returns true whenever it finds any node that doesn't match the specified name, which happens in every multi-node trace.
Answer
Unfortunately, LangSmith doesn't currently support directly excluding entire traces that contain a specific node name through query filters alone. The tree_filter parameter with neq doesn't work for this use case because it checks if ANY run in the trace tree matches the condition, and will always find nodes that don't match your excluded name.
Here are three workaround approaches you can use:
Option 1: Post-process results (Most reliable)
Fetch the traces and filter them in your application code:
from langsmith import Client
client = Client()
# Fetch all matching root runs
runs = list(client.list_runs(
project_name="your_project",
filter='and(eq(thread_id, "your_thread_id"), like(inputs, "%credit%"), eq(is_root, true))'
))
# Filter out traces containing the unwanted node
filtered_runs = []
for run in runs:
# Get all runs in this trace
trace_runs = list(client.list_runs(trace_id=run.trace_id))
# Exclude if any run has the unwanted name
if not any(r.name == "unwanted_node_name" for r in trace_runs):
filtered_runs.append(run)Option 2: Tag-based filtering (Best long-term solution)
If you control the trace creation code, add tags to mark traces that contain specific nodes:
# When creating traces, add a tag
with traceable(tags=["has_specific_node"]):
# your code that calls the specific node
pass
# Then fetch all runs and filter in code for those without the tagOption 3: Use metadata markers
Add metadata to your root runs indicating which nodes were executed:
# During trace creation
metadata = {"executed_nodes": ["node1", "node2", "specific_node_name"]}
# Then query and filter in application code based on metadataSources:
Trace Query Syntax - Documents available filter operators
Query Traces SDK - Examples of tree_filter usage