To improve the formatting of conversations in Phoenix sessions when using LangChain, ensure that only the relevant user/assistant messages are passed as the input to the LLM, and avoid including extra context or parameters in the messages list. The Phoenix UI displays whatever is sent as input, so if you include additional parameters (like context or other metadata) in the messages, they will appear in the conversation view. Structure your input so that only the intended chat messages are included, as shown in the <https://docs.arize.com/phoenix/tracing/how-to-tracing/setup-tracing/setup-sessions#B%3A8|LangChain and Phoenix session docs>.
If you are using custom payloads or passing extra fields, refactor your code to separate system/user/assistant messages from other parameters. For example, use a list of message objects with only "role" and "content" fields for the conversation, and pass other data (like context) separately if needed. See the <https://docs.arize.com/phoenix/tracing/how-to-tracing/setup-tracing/setup-sessions#B%3A8|example in the Phoenix docs> for the recommended structure.
Would you like a code example for this?
Sources:
- <https://docs.arize.com/phoenix/tracing/how-to-tracing/setup-tracing/setup-sessions#B%3A8|How to track sessions with LangChain>
- <https://github.com/Arize-ai/phoenix/issues/3106|LangChain session formatting issue discussion>