test__format_messages_trailing_whitespace() — langchain Function Reference
Architecture documentation for the test__format_messages_trailing_whitespace() function in test_chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD b928ae05_a8f8_b52e_4f1f_8c2cb3b88876["test__format_messages_trailing_whitespace()"] 18428dc5_a41b_90c6_88ad_615296ee3311["test_chat_models.py"] b928ae05_a8f8_b52e_4f1f_8c2cb3b88876 -->|defined in| 18428dc5_a41b_90c6_88ad_615296ee3311 style b928ae05_a8f8_b52e_4f1f_8c2cb3b88876 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/anthropic/tests/unit_tests/test_chat_models.py lines 2286–2303
def test__format_messages_trailing_whitespace() -> None:
"""Test that trailing whitespace is trimmed from the final assistant message."""
human = HumanMessage("foo") # type: ignore[misc]
# Test string content
ai_string = AIMessage("thought ") # type: ignore[misc]
_, anthropic_messages = _format_messages([human, ai_string])
assert anthropic_messages[-1]["content"] == "thought"
# Test list content
ai_list = AIMessage([{"type": "text", "text": "thought "}]) # type: ignore[misc]
_, anthropic_messages = _format_messages([human, ai_list])
assert anthropic_messages[-1]["content"][0]["text"] == "thought" # type: ignore[index]
# Test that intermediate messages are NOT trimmed
ai_intermediate = AIMessage("thought ") # type: ignore[misc]
_, anthropic_messages = _format_messages([human, ai_intermediate, human])
assert anthropic_messages[1]["content"] == "thought "
Domain
Subdomains
Source
Frequently Asked Questions
What does test__format_messages_trailing_whitespace() do?
test__format_messages_trailing_whitespace() is a function in the langchain codebase, defined in libs/partners/anthropic/tests/unit_tests/test_chat_models.py.
Where is test__format_messages_trailing_whitespace() defined?
test__format_messages_trailing_whitespace() is defined in libs/partners/anthropic/tests/unit_tests/test_chat_models.py at line 2286.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free