get_final_text() — anthropic-sdk-python Function Reference
Architecture documentation for the get_final_text() function in _messages.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD 1bc68915_5733_1542_a79b_791f2a5ac05e["get_final_text()"] e621e870_ca7f_408e_c8bb_3d408ede66a4["MessageStream"] 1bc68915_5733_1542_a79b_791f2a5ac05e -->|defined in| e621e870_ca7f_408e_c8bb_3d408ede66a4 85eb3149_498e_f553_00e0_c28342315541["get_final_text()"] 85eb3149_498e_f553_00e0_c28342315541 -->|calls| 1bc68915_5733_1542_a79b_791f2a5ac05e f7d7eda3_f48d_9a94_ee86_5e96ba366fee["get_final_message()"] 1bc68915_5733_1542_a79b_791f2a5ac05e -->|calls| f7d7eda3_f48d_9a94_ee86_5e96ba366fee 85eb3149_498e_f553_00e0_c28342315541["get_final_text()"] 1bc68915_5733_1542_a79b_791f2a5ac05e -->|calls| 85eb3149_498e_f553_00e0_c28342315541 style 1bc68915_5733_1542_a79b_791f2a5ac05e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/anthropic/lib/streaming/_messages.py lines 97–116
def get_final_text(self) -> str:
"""Returns all `text` content blocks concatenated together.
> [!NOTE]
> Currently the API will only respond with a single content block.
Will raise an error if no `text` content blocks were returned.
"""
message = self.get_final_message()
text_blocks: list[str] = []
for block in message.content:
if block.type == "text":
text_blocks.append(block.text)
if not text_blocks:
raise RuntimeError(
f".get_final_text() can only be called when the API returns a `text` content block.\nThe API returned {','.join([b.type for b in message.content])} content block type(s) that you can access by calling get_final_message().content"
)
return "".join(text_blocks)
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does get_final_text() do?
get_final_text() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/lib/streaming/_messages.py.
Where is get_final_text() defined?
get_final_text() is defined in src/anthropic/lib/streaming/_messages.py at line 97.
What does get_final_text() call?
get_final_text() calls 2 function(s): get_final_message, get_final_text.
What calls get_final_text()?
get_final_text() is called by 1 function(s): get_final_text.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free