Home / Class/ TestReasoningJsonOutputParser Class — langchain Architecture

TestReasoningJsonOutputParser Class — langchain Architecture

Architecture documentation for the TestReasoningJsonOutputParser class in test_output_parsers.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  dd46aa2b_85a9_6271_a241_97400f51b41f["TestReasoningJsonOutputParser"]
  0dd75536_e009_da4d_0090_3d46069fce40["OutputParserException"]
  dd46aa2b_85a9_6271_a241_97400f51b41f -->|extends| 0dd75536_e009_da4d_0090_3d46069fce40
  404c4f2e_2e78_7429_00c2_95ca3f208765["test_output_parsers.py"]
  dd46aa2b_85a9_6271_a241_97400f51b41f -->|defined in| 404c4f2e_2e78_7429_00c2_95ca3f208765
  5709e35a_15af_693f_75c9_38bde00decfd["test_parse_json_without_think_tags()"]
  dd46aa2b_85a9_6271_a241_97400f51b41f -->|method| 5709e35a_15af_693f_75c9_38bde00decfd
  6f56f838_3d5f_bb59_b135_9114ce8d8c29["test_parse_json_with_think_tags()"]
  dd46aa2b_85a9_6271_a241_97400f51b41f -->|method| 6f56f838_3d5f_bb59_b135_9114ce8d8c29
  f47be6f7_dc9d_4877_3bc4_71cb0ef5ef41["test_parse_json_with_multiple_think_tags()"]
  dd46aa2b_85a9_6271_a241_97400f51b41f -->|method| f47be6f7_dc9d_4877_3bc4_71cb0ef5ef41
  e8b94a64_a90a_3fbe_e9fc_bff74f23594f["test_parse_markdown_json_with_think_tags()"]
  dd46aa2b_85a9_6271_a241_97400f51b41f -->|method| e8b94a64_a90a_3fbe_e9fc_bff74f23594f
  c6e7a715_73b9_023c_812d_0b22aa715c81["test_parse_complex_json_with_think_tags()"]
  dd46aa2b_85a9_6271_a241_97400f51b41f -->|method| c6e7a715_73b9_023c_812d_0b22aa715c81
  db582975_4a03_61ed_b196_a1f0e5f86f4b["test_parse_invalid_json_with_think_tags()"]
  dd46aa2b_85a9_6271_a241_97400f51b41f -->|method| db582975_4a03_61ed_b196_a1f0e5f86f4b
  437c1393_3051_42b2_e3e1_d1b8b84728f4["test_parse_empty_string_after_stripping()"]
  dd46aa2b_85a9_6271_a241_97400f51b41f -->|method| 437c1393_3051_42b2_e3e1_d1b8b84728f4
  d6f2072a_c49c_814f_1bcf_fbf86993d35e["test_parse_json_array_with_think_tags()"]
  dd46aa2b_85a9_6271_a241_97400f51b41f -->|method| d6f2072a_c49c_814f_1bcf_fbf86993d35e
  06ea16fa_bb51_791c_d5fa_1db8a3f20d43["test_partial_json_parsing_with_think_tags()"]
  dd46aa2b_85a9_6271_a241_97400f51b41f -->|method| 06ea16fa_bb51_791c_d5fa_1db8a3f20d43

Relationship Graph

Source Code

libs/partners/perplexity/tests/unit_tests/test_output_parsers.py lines 82–172

class TestReasoningJsonOutputParser:
    """Tests for ReasoningJsonOutputParser."""

    def test_parse_json_without_think_tags(self) -> None:
        """Test parsing JSON without think tags."""
        parser = ReasoningJsonOutputParser()
        text = '{"name": "John", "age": 30}'
        generation = Generation(text=text)
        result = parser.parse_result([generation])
        assert result == {"name": "John", "age": 30}

    def test_parse_json_with_think_tags(self) -> None:
        """Test parsing JSON with think tags."""
        parser = ReasoningJsonOutputParser()
        text = '<think>Let me construct the JSON</think>{"name": "John", "age": 30}'
        generation = Generation(text=text)
        result = parser.parse_result([generation])
        assert result == {"name": "John", "age": 30}

    def test_parse_json_with_multiple_think_tags(self) -> None:
        """Test parsing JSON with multiple think tags."""
        parser = ReasoningJsonOutputParser()
        text = '<think>Step 1</think>{"name": <think>thinking</think>"John", "age": 30}'
        generation = Generation(text=text)
        result = parser.parse_result([generation])
        assert result == {"name": "John", "age": 30}

    def test_parse_markdown_json_with_think_tags(self) -> None:
        """Test parsing markdown-wrapped JSON with think tags."""
        parser = ReasoningJsonOutputParser()
        text = """<think>Building response</think>
```json
{"name": "John", "age": 30}
```"""
        generation = Generation(text=text)
        result = parser.parse_result([generation])
        assert result == {"name": "John", "age": 30}

    def test_parse_complex_json_with_think_tags(self) -> None:
        """Test parsing complex nested JSON with think tags."""
        parser = ReasoningJsonOutputParser()
        text = """<think>Creating nested structure</think>
{
    "user": {
        "name": "John",
        "address": {
            "city": "NYC",
            "zip": "10001"
        }
    },
    "items": [1, 2, 3]
}"""
        generation = Generation(text=text)
        result = parser.parse_result([generation])
        assert result == {
            "user": {"name": "John", "address": {"city": "NYC", "zip": "10001"}},
            "items": [1, 2, 3],
        }

    def test_parse_invalid_json_with_think_tags(self) -> None:
        """Test that invalid JSON raises an exception even with think tags."""
        parser = ReasoningJsonOutputParser()
        text = "<think>This will fail</think>{invalid json}"
        generation = Generation(text=text)
        with pytest.raises(OutputParserException):
            parser.parse_result([generation])

    def test_parse_empty_string_after_stripping(self) -> None:
        """Test parsing when only think tags remain."""
        parser = ReasoningJsonOutputParser()
        text = "<think>Only reasoning, no output</think>"
        generation = Generation(text=text)
        with pytest.raises(OutputParserException):
            parser.parse_result([generation])

    def test_parse_json_array_with_think_tags(self) -> None:
        """Test parsing JSON array with think tags."""
        parser = ReasoningJsonOutputParser()
        text = '<think>Creating array</think>[{"id": 1}, {"id": 2}]'
        generation = Generation(text=text)
        result = parser.parse_result([generation])

Frequently Asked Questions

What is the TestReasoningJsonOutputParser class?
TestReasoningJsonOutputParser is a class in the langchain codebase, defined in libs/partners/perplexity/tests/unit_tests/test_output_parsers.py.
Where is TestReasoningJsonOutputParser defined?
TestReasoningJsonOutputParser is defined in libs/partners/perplexity/tests/unit_tests/test_output_parsers.py at line 82.
What does TestReasoningJsonOutputParser extend?
TestReasoningJsonOutputParser extends OutputParserException.

Analyze Your Own Codebase

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

Try Supermodel Free