Home / Function/ test_jinja2_blocked_standalone_prompt_template() — langchain Function Reference

test_jinja2_blocked_standalone_prompt_template() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/core/tests/unit_tests/load/test_serializable.py lines 823–860

    def test_jinja2_blocked_standalone_prompt_template(self) -> None:
        """Test blocking Jinja2 on standalone `PromptTemplate`."""
        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_standalone_prompt_template() do?
test_jinja2_blocked_standalone_prompt_template() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/load/test_serializable.py.
Where is test_jinja2_blocked_standalone_prompt_template() defined?
test_jinja2_blocked_standalone_prompt_template() is defined in libs/core/tests/unit_tests/load/test_serializable.py at line 823.

Analyze Your Own Codebase

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

Try Supermodel Free