Skip to content

Commit

Permalink
base_prompt: Remove warning on old schema
Browse files Browse the repository at this point in the history
  • Loading branch information
irgolic committed Nov 21, 2023
1 parent 58d2316 commit d34dfbd
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 39 deletions.
14 changes: 0 additions & 14 deletions guardrails/prompt/base_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.<constant_name>}
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.<constant_name>}
Expand All @@ -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

Expand Down
25 changes: 0 additions & 25 deletions tests/unit_tests/test_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit d34dfbd

Please sign in to comment.