Home / Function/ test_jinja2_template_blocked() — langchain Function Reference

test_jinja2_template_blocked() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/core/tests/unit_tests/load/test_serializable.py lines 771–821

    def test_jinja2_template_blocked(self) -> None:
        """Test that Jinja2 templates are blocked by default."""
        # Malicious serialized payload attempting to use jinja2
        malicious_serialized = {
            "lc": 1,
            "type": "constructor",
            "id": ["langchain", "prompts", "chat", "ChatPromptTemplate"],
            "kwargs": {
                "input_variables": ["name"],
                "messages": [
                    {
                        "lc": 1,
                        "type": "constructor",
                        "id": [
                            "langchain",
                            "prompts",
                            "chat",
                            "HumanMessagePromptTemplate",
                        ],
                        "kwargs": {
                            "prompt": {
                                "lc": 1,
                                "type": "constructor",
                                "id": [
                                    "langchain",
                                    "prompts",
                                    "prompt",
                                    "PromptTemplate",
                                ],
                                "kwargs": {
                                    "input_variables": ["name"],
                                    "template": "{{ name }}",
                                    "template_format": "jinja2",
                                },
                            }
                        },
                    }
                ],
            },
        }

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

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free