Home / File/ test_output_parsers.py — langchain Source File

test_output_parsers.py — langchain Source File

Architecture documentation for test_output_parsers.py, a python file in the langchain codebase. 5 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  6ff9f933_1fb8_e336_8203_aa7be2f1666d["test_output_parsers.py"]
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  6ff9f933_1fb8_e336_8203_aa7be2f1666d --> 120e2591_3e15_b895_72b6_cb26195e40a6
  75137834_4ba7_dc43_7ec5_182c05eceedf["langchain_core.exceptions"]
  6ff9f933_1fb8_e336_8203_aa7be2f1666d --> 75137834_4ba7_dc43_7ec5_182c05eceedf
  ac2a9b92_4484_491e_1b48_ec85e71e1d58["langchain_core.outputs"]
  6ff9f933_1fb8_e336_8203_aa7be2f1666d --> ac2a9b92_4484_491e_1b48_ec85e71e1d58
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  6ff9f933_1fb8_e336_8203_aa7be2f1666d --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  ddd8a729_2dab_2b60_3ab9_77ec0991eea9["langchain_perplexity.output_parsers"]
  6ff9f933_1fb8_e336_8203_aa7be2f1666d --> ddd8a729_2dab_2b60_3ab9_77ec0991eea9
  style 6ff9f933_1fb8_e336_8203_aa7be2f1666d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Unit tests for output parsers."""

import pytest
from langchain_core.exceptions import OutputParserException
from langchain_core.outputs import Generation
from pydantic import BaseModel, Field

from langchain_perplexity.output_parsers import (
    ReasoningJsonOutputParser,
    ReasoningStructuredOutputParser,
    strip_think_tags,
)


class TestStripThinkTags:
    """Tests for the strip_think_tags function."""

    def test_strip_simple_think_tags(self) -> None:
        """Test stripping simple think tags."""
        text = "Hello <think>some reasoning</think> world"
        result = strip_think_tags(text)
        assert result == "Hello  world"

    def test_strip_multiple_think_tags(self) -> None:
        """Test stripping multiple think tags."""
        text = "<think>first</think> Hello <think>second</think> world\
            <think>third</think>"
        result = strip_think_tags(text)
        assert result == "Hello  world"

    def test_strip_nested_like_think_tags(self) -> None:
        """Test stripping think tags that might appear nested."""
        text = "<think>outer <think>inner</think> still outer</think> result"
        result = strip_think_tags(text)
        # The function removes from first <think> to first </think>
        # then continues from after that </think>
        assert result == "still outer</think> result"

    def test_strip_think_tags_no_closing_tag(self) -> None:
        """Test handling of think tags without closing tag."""
        text = "Hello <think>unclosed reasoning world"
        result = strip_think_tags(text)
        # Treats unclosed tag as literal text
        assert result == "Hello <think>unclosed reasoning world"

    def test_strip_think_tags_empty_content(self) -> None:
        """Test stripping empty think tags."""
        text = "Hello <think></think> world"
        result = strip_think_tags(text)
        assert result == "Hello  world"

    def test_strip_think_tags_no_tags(self) -> None:
        """Test text without any think tags."""
        text = "Hello world"
        result = strip_think_tags(text)
        assert result == "Hello world"

    def test_strip_think_tags_only_tags(self) -> None:
        """Test text containing only think tags."""
        text = "<think>reasoning</think>"
// ... (297 more lines)

Subdomains

Dependencies

  • langchain_core.exceptions
  • langchain_core.outputs
  • langchain_perplexity.output_parsers
  • pydantic
  • pytest

Frequently Asked Questions

What does test_output_parsers.py do?
test_output_parsers.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What does test_output_parsers.py depend on?
test_output_parsers.py imports 5 module(s): langchain_core.exceptions, langchain_core.outputs, langchain_perplexity.output_parsers, pydantic, pytest.
Where is test_output_parsers.py in the architecture?
test_output_parsers.py is located at libs/partners/perplexity/tests/unit_tests/test_output_parsers.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/partners/perplexity/tests/unit_tests).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free