Topics classify your traces by running an LLM over a normalized text representation of each trace. That representation comes from a preprocessor, and the built-in Thread preprocessor (the default) handles most traces out of the box. This guide covers confirming your traces render correctly, enabling Topics, and adapting traces that need a custom preprocessor.Documentation Index
Fetch the complete documentation index at: https://braintrust.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
Check your traces
Before enabling Topics, confirm a representative trace renders correctly through the Thread preprocessor:- Go to Logs and open a trace.
- Select the Thread view.
- Select and choose the Thread preprocessor.
- Confirm the conversation renders with the user turns, assistant turns, and tool calls you expect.
Enable Topics
Once your traces pass the check above, enabling Topics turns on the built-in facets (Task, Sentiment, Issues) for the current project and starts the daily pipeline:- Go to Topics.
- Choose whether to Apply to existing traces or only to new traces.
- Click Enable topics.
When traces don’t work
If the check above didn’t produce a conversation, the Thread preprocessor couldn’t extract messages from your trace. The preprocessor walks every non-scorer span, readsinput and output, converts recognized message data into role/content pairs, and deduplicates across spans.
Each span uses OpenAI-style role/content messages: an array of messages on input, and the assistant message object on output:
- Conversation in metadata: Messages stored in
metadatainstead ofinputoroutput. - Custom field names without
role: Objects using names likeuser_questionandassistant_replyinstead ofroleandcontent. - Flattened strings: A turn collapsed into a single string like
"USER: ... \nASSISTANT: ...". - Deeply nested wrappers: Messages buried below the recognized wrapper keys (
messages,prompt,input,output,choices,result,response), likedata.payload.messages. - LangGraph state without message arrays: Graph state that doesn’t expose a recognized message array.
Update your instrumentation
If you control how spans are logged, adjustinput and output so they match a recognized shape. Common fixes for the patterns above:
- Conversation in metadata: Move messages from
metadatatoinputandoutput. - Custom field names without
role: Rename fields torole/content, or wrap them under a recognized key likemessages. - Flattened strings: Emit a message array instead of a single concatenated string.
- Deeply nested wrappers: Unwrap so one of the recognized keys sits at the top level.
- LangGraph state without message arrays: Include the underlying LangChain or OpenAI-style messages on the spans you want Topics to see.
Write a custom preprocessor
A custom preprocessor is a function namedhandler that receives a span’s fields (input, output, metadata, error, span_attributes) and returns a message array Topics can use. Each example below addresses one of the patterns listed above and can be pasted directly into the preprocessor editor.
Conversation in metadata
Conversation in metadata
Trace shape:Preprocessor:
Custom field names
Custom field names
Trace shape:Preprocessor:
Flattened strings
Flattened strings
Trace shape:Preprocessor:
Deeply nested wrappers
Deeply nested wrappers
Trace shape:Preprocessor:
LangGraph state
LangGraph state
Trace shape:Preprocessor:
- Go to Logs and open any trace.
- Select Thread to switch to the Thread view.
- Select to open the preprocessor picker, then choose + Custom preprocessor (advanced) at the bottom of the dropdown.
- Paste or write your function, enter a name, and click Save.
- Verify the Thread view now renders the conversation correctly using your preprocessor. Iterate on the function until it does.
- Go to Settings > Advanced and select your preprocessor under Default preprocessor. Topics will use it for every facet that doesn’t override the preprocessor, including the built-in Task, Sentiment, and Issues facets.
Next steps
- Review insights once classifications appear.
- Manage Topics by checking pipeline status, re-generating topics, and adjusting sampling.
- Create custom facets for domain-specific patterns beyond the built-in facets.