Skip to content

Commit e80ba5c

Browse files
committed
base_prompt: Remove warning on old schema
1 parent 58d2316 commit e80ba5c

File tree

2 files changed

+0
-41
lines changed

2 files changed

+0
-41
lines changed

guardrails/prompt/base_prompt.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Class for representing a prompt entry."""
22
import re
3-
import warnings
43
from string import Template
54
from typing import Optional
65

@@ -48,13 +47,6 @@ def substitute_constants(self, text):
4847
"""Substitute constants in the prompt."""
4948
# Substitute constants by reading the constants file.
5049
# Regex to extract all occurrences of ${gr.<constant_name>}
51-
if self.uses_old_constant_schema(text):
52-
warnings.warn(
53-
"It appears that you are using an old schema for gaurdrails variables, "
54-
"follow the new namespaced convention "
55-
"documented here: https://docs.guardrailsai.com/0-2-migration/"
56-
)
57-
5850
matches = re.findall(r"\${gr\.(\w+)}", text)
5951

6052
# Substitute all occurrences of ${gr.<constant_name>}
@@ -66,13 +58,6 @@ def substitute_constants(self, text):
6658

6759
return text
6860

69-
def uses_old_constant_schema(self, text) -> bool:
70-
matches = re.findall(r"@(\w+)", text)
71-
if len(matches) == 0:
72-
return False
73-
else:
74-
return True
75-
7661
def get_prompt_variables(self):
7762
return self.variable_names
7863

tests/unit_tests/test_prompt.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Unit tests for prompt and instructions parsing."""
22

33
from string import Template
4-
from unittest import mock
54

65
import pytest
76
from pydantic import BaseModel, Field
@@ -232,31 +231,6 @@ def test_substitute_constants(prompt_str, final_prompt):
232231
assert prompt.source == final_prompt
233232

234233

235-
# TODO: Deprecate when we can confirm migration off the old, non-namespaced standard
236-
@pytest.mark.parametrize(
237-
"text, is_old_schema",
238-
[
239-
(RAIL_WITH_OLD_CONSTANT_SCHEMA, True), # Test with a single match
240-
(
241-
RAIL_WITH_FORMAT_INSTRUCTIONS,
242-
False,
243-
), # Test with no matches/correct namespacing
244-
],
245-
)
246-
def test_uses_old_constant_schema(text, is_old_schema):
247-
with mock.patch("warnings.warn") as warn_mock:
248-
guard = gd.Guard.from_rail_string(text)
249-
assert guard.prompt.uses_old_constant_schema(text) == is_old_schema
250-
if is_old_schema:
251-
# we only check for the warning when we have an older schema
252-
warn_mock.assert_called_once_with(
253-
"""It appears that you are using an old schema for gaurdrails\
254-
variables, follow the new namespaced convention documented here:\
255-
https://docs.guardrailsai.com/0-2-migration/\
256-
"""
257-
)
258-
259-
260234
class TestResponse(BaseModel):
261235
grade: int = Field(description="The grade of the response")
262236

0 commit comments

Comments
 (0)