Home / Function/ test_jinja2_blocked_by_default() — langchain Function Reference

test_jinja2_blocked_by_default() — langchain Function Reference

Architecture documentation for the test_jinja2_blocked_by_default() function in test_serializable.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  22a45c8c_316d_af50_d20a_b826005c829d["test_jinja2_blocked_by_default()"]
  6eac7a3c_5af8_e95a_bd3e_ee52ea07b9b0["TestJinja2SecurityBlocking"]
  22a45c8c_316d_af50_d20a_b826005c829d -->|defined in| 6eac7a3c_5af8_e95a_bd3e_ee52ea07b9b0
  style 22a45c8c_316d_af50_d20a_b826005c829d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/load/test_serializable.py lines 862–893

    def test_jinja2_blocked_by_default(self) -> None:
        """Test that Jinja2 templates are blocked by default."""
        serialized_jinja2 = {
            "lc": 1,
            "type": "constructor",
            "id": ["langchain", "prompts", "prompt", "PromptTemplate"],
            "kwargs": {
                "input_variables": ["name"],
                "template": "{{ name }}",
                "template_format": "jinja2",
            },
        }

        serialized_fstring = {
            "lc": 1,
            "type": "constructor",
            "id": ["langchain", "prompts", "prompt", "PromptTemplate"],
            "kwargs": {
                "input_variables": ["name"],
                "template": "{name}",
                "template_format": "f-string",
            },
        }

        # f-string should work
        loaded = load(serialized_fstring, allowed_objects=[PromptTemplate])
        assert isinstance(loaded, PromptTemplate)
        assert loaded.template == "{name}"

        # jinja2 should be blocked by default
        with pytest.raises(ValueError, match="Jinja2 templates are not allowed"):
            load(serialized_jinja2, allowed_objects=[PromptTemplate])

Domain

Subdomains

Frequently Asked Questions

What does test_jinja2_blocked_by_default() do?
test_jinja2_blocked_by_default() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/load/test_serializable.py.
Where is test_jinja2_blocked_by_default() defined?
test_jinja2_blocked_by_default() is defined in libs/core/tests/unit_tests/load/test_serializable.py at line 862.

Analyze Your Own Codebase

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

Try Supermodel Free