How to delete traces or runs?

When a user deletes their account I want to delete all the user data on langsmith.

I have run ids stored in my db. How do I delete all traces/runs of that user based on these run ids?

LangSmith doesn’t have a direct bulk delete API for runs. You’ll need to delete runs individually using the LangSmith SDK:

from langsmith import Client

client = Client()
for run_id in user_run_ids:
    try:
        client.delete_run(run_id)
    except Exception as e:
        # Handle errors (run might not exist)
        continue

For large datasets, batch this operation and add rate limiting to avoid API limits. Alternatively, contact LangSmith support for bulk deletion assistance if you have thousands of runs. Note that deleted runs may still appear in aggregated metrics but individual trace data will be removed.

1 Like

There is a batch delete endpoint that you can access through the API here

Thanks!

I tried using this and I get asked for a session_id that does not exist for my traces, why can’t I delete just using the trace_id?

Hi @mariana

session_id is just the project ID for the trace you are trying to delete. You can find it on the tracer project page

thank you! I used session_id before, but it was related to threads

Even though I have done this I get “Run deletes queued", but nothing gets deleted. I have no way to debug because even if I pass a wrong id it still says the same

Trace deletions are processed during non-peak usage times and are not instant, usually within a few hours. There is no confirmation of deletion - you’ll need to query the data again to verify it has been removed.

We process these deletions over the weekend now