From d34dfbdf109d9a6db89ea98a44407758ded9db98 Mon Sep 17 00:00:00 2001 From: Rafael Irgolic Date: Tue, 21 Nov 2023 17:37:35 +0000 Subject: [PATCH] base_prompt: Remove warning on old schema --- guardrails/prompt/base_prompt.py | 14 -------------- tests/unit_tests/test_prompt.py | 25 ------------------------- 2 files changed, 39 deletions(-) diff --git a/guardrails/prompt/base_prompt.py b/guardrails/prompt/base_prompt.py index 643313eff..985ac0699 100644 --- a/guardrails/prompt/base_prompt.py +++ b/guardrails/prompt/base_prompt.py @@ -48,13 +48,6 @@ def substitute_constants(self, text): """Substitute constants in the prompt.""" # Substitute constants by reading the constants file. # Regex to extract all occurrences of ${gr.} - if self.uses_old_constant_schema(text): - warnings.warn( - "It appears that you are using an old schema for gaurdrails variables, " - "follow the new namespaced convention " - "documented here: https://docs.guardrailsai.com/0-2-migration/" - ) - matches = re.findall(r"\${gr\.(\w+)}", text) # Substitute all occurrences of ${gr.} @@ -66,13 +59,6 @@ def substitute_constants(self, text): return text - def uses_old_constant_schema(self, text) -> bool: - matches = re.findall(r"@(\w+)", text) - if len(matches) == 0: - return False - else: - return True - def get_prompt_variables(self): return self.variable_names diff --git a/tests/unit_tests/test_prompt.py b/tests/unit_tests/test_prompt.py index 40f2d1c08..78fa02bd6 100644 --- a/tests/unit_tests/test_prompt.py +++ b/tests/unit_tests/test_prompt.py @@ -232,31 +232,6 @@ def test_substitute_constants(prompt_str, final_prompt): assert prompt.source == final_prompt -# TODO: Deprecate when we can confirm migration off the old, non-namespaced standard -@pytest.mark.parametrize( - "text, is_old_schema", - [ - (RAIL_WITH_OLD_CONSTANT_SCHEMA, True), # Test with a single match - ( - RAIL_WITH_FORMAT_INSTRUCTIONS, - False, - ), # Test with no matches/correct namespacing - ], -) -def test_uses_old_constant_schema(text, is_old_schema): - with mock.patch("warnings.warn") as warn_mock: - guard = gd.Guard.from_rail_string(text) - assert guard.prompt.uses_old_constant_schema(text) == is_old_schema - if is_old_schema: - # we only check for the warning when we have an older schema - warn_mock.assert_called_once_with( - """It appears that you are using an old schema for gaurdrails\ - variables, follow the new namespaced convention documented here:\ - https://docs.guardrailsai.com/0-2-migration/\ -""" - ) - - class TestResponse(BaseModel): grade: int = Field(description="The grade of the response")