本指南介绍数据到达 LangSmith Cloud 服务器后可用的各种功能,以帮助您实现隐私目标。

数据保留

LangSmith 提供自动数据保留功能以帮助合规和存储管理。数据保留策略可以在组织和项目级别配置。 有关数据保留配置和管理的详细信息,请参阅数据保留概念文档。

跟踪删除

您可以使用 API 完成跟踪删除。API 支持两种删除跟踪的方法:
  1. 按跟踪 ID 和会话 ID:通过提供跟踪 ID 列表及其相应的会话 ID 删除特定跟踪(每个请求最多 1000 条跟踪)
  2. 按元数据:删除工作区中与任何指定元数据键值对匹配的跟踪
有关更多详细信息,请参阅 API 规范
所有跟踪删除都将删除所有数据存储中的相关实体,如反馈、聚合和统计信息。

Deletion timeline

Trace deletions are processed during non-peak usage times and are not instant. LangChain runs the delete job on the weekend. There is no confirmation of deletion - you’ll need to query the data again to verify it has been removed.

Delete specific traces

To delete specific traces by their trace IDs from a single session:
curl -X POST "https://api.smith.langchain.com/api/v1/runs/delete" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "trace_ids": ["trace-id-1", "trace-id-2", "trace-id-3"],
    "session_id": "session-id-1"
  }'

Delete by metadata

When deleting by metadata:
  • Accepts a metadata object of key/value pairs. KV pair matching uses an or condition. A trace will match if it has any of the key-value pairs specified in metadata (not all)
  • You don’t need to specify a session id when deleting by metadata. Deletes will apply across the workspace.
To delete traces based on metadata across a workspace (matches any of the metadata key-value pairs):
curl -X POST "https://api.smith.langchain.com/api/v1/runs/delete" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "metadata": {
      "user_id": "user123",
      "environment": "staging"
    }
  }'
This will delete traces that have either user_id: "user123" or environment: "staging" in their metadata.
Remember that you can only schedule up to 1000 traces per session per request. For larger deletions, you’ll need to make multiple requests.

Example deletes

You can delete dataset examples self-serve via our API, which supports both soft and hard deletion methods depending on your data retention needs.
Hard deletes will permanently remove inputs, outputs, and metadata from ALL versions of the specified examples across the entire dataset history.

Deleting examples is a two-step process

For bulk operations, example deletion follows a two-step process:

1. Search for examples by metadata

Find all examples with matching metadata across all datasets in a workspace. GET /examples
  • as_of must be explicitly specified as a timestamp. Only examples created before the as_of date will be returned
curl -X GET "https://api.smith.langchain.com/api/v1/examples?as_of=2024-01-01T00:00:00Z" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "metadata": {
      "user_id": "user123",
      "environment": "staging"
    }
  }'
This will return examples that have either user_id: "user123" or environment: "staging" in their metadata across all datasets in your workspace.

2. Hard delete examples

Once you have the example IDs, send a delete request. This will zero-out the inputs, outputs, and metadata from all versions of the dataset for that example. DELETE /examples
  • Specify example IDs and add "hard_delete": true to the query params of the request
curl -X DELETE "https://api.smith.langchain.com/api/v1/examples?hard_delete=true" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "example_ids": ["example-id-1", "example-id-2", "example-id-3"]
  }'

Deletion types

Soft delete (default)

  • Creates tombstoned entries with NULL inputs/outputs in the dataset
  • Preserves historical data and maintains dataset versioning
  • Only affects the current version of the dataset

Hard delete

  • Permanently removes inputs, outputs, and metadata from ALL dataset versions
  • Complete data removal when compliance requires zero-out across all versions
  • Add "hard_delete": true to the query parameters
For more details, refer to the API spec.
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.