strip_think_tags() — langchain Function Reference
Architecture documentation for the strip_think_tags() function in output_parsers.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD b2204b0d_d186_cc64_ba3a_c35b30d16454["strip_think_tags()"] 1be78f27_fe4d_35ef_90f6_0cba68eb107b["output_parsers.py"] b2204b0d_d186_cc64_ba3a_c35b30d16454 -->|defined in| 1be78f27_fe4d_35ef_90f6_0cba68eb107b 226e3323_bb76_2676_e692_4e21f7ba7236["parse_result()"] 226e3323_bb76_2676_e692_4e21f7ba7236 -->|calls| b2204b0d_d186_cc64_ba3a_c35b30d16454 9a2ae530_422d_2fd8_fa7d_2515e0623c7c["parse_result()"] 9a2ae530_422d_2fd8_fa7d_2515e0623c7c -->|calls| b2204b0d_d186_cc64_ba3a_c35b30d16454 style b2204b0d_d186_cc64_ba3a_c35b30d16454 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/perplexity/langchain_perplexity/output_parsers.py lines 9–35
def strip_think_tags(text: str) -> str:
"""Removes all <think>...</think> tags and their content from text.
This function removes all occurrences of think tags, preserving text
before, between, and after the tags. It also handles markdown code fences.
Args:
text: The input text that may contain think tags.
Returns:
The text with all `<think>...</think>` blocks removed.
"""
# Remove all <think>...</think> blocks using regex
# The pattern matches <think> followed by any content (non-greedy) until </think>
result = re.sub(r"<think>.*?</think>", "", text, flags=re.DOTALL)
# Remove markdown code fence markers if present
result = result.strip()
if result.startswith("```json"):
result = result[len("```json") :].strip()
elif result.startswith("```"):
result = result[3:].strip()
if result.endswith("```"):
result = result[:-3].strip()
return result
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does strip_think_tags() do?
strip_think_tags() is a function in the langchain codebase, defined in libs/partners/perplexity/langchain_perplexity/output_parsers.py.
Where is strip_think_tags() defined?
strip_think_tags() is defined in libs/partners/perplexity/langchain_perplexity/output_parsers.py at line 9.
What calls strip_think_tags()?
strip_think_tags() is called by 2 function(s): parse_result, parse_result.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free