Skip to content
2 changes: 1 addition & 1 deletion guardrails/applications/text2sql.rail
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<rail version="0.1">
<output>
<sql
<string
name="generated_sql"
description="Generate SQL for the given natural language instruction."
format="bug-free-sql: ${conn_str} ${schema_file}"
Expand Down
82 changes: 1 addition & 81 deletions guardrails/datatypes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import datetime
import warnings
from dataclasses import dataclass
from types import SimpleNamespace
from typing import Any, Dict, Iterable
Expand All @@ -15,15 +14,6 @@
from guardrails.validator_base import Validator, ValidatorSpec
from guardrails.validatorsattr import ValidatorsAttr

# TODO - deprecate these altogether
deprecated_string_types = {"sql", "email", "url", "pythoncode"}


def update_deprecated_type_to_string(type):
if type in deprecated_string_types:
return "string"
return type


@dataclass
class FieldValidation:
Expand Down Expand Up @@ -165,16 +155,6 @@ def decorator(cls: T) -> T:
return decorator


# Decorator for deprecation
def deprecate_type(cls: type):
warnings.warn(
f"""The '{cls.__name__}' type is deprecated and will be removed in \
versions 0.3.0 and beyond. Use the pydantic 'str' primitive instead.""",
DeprecationWarning,
)
return cls


class ScalarType(DataType):
def set_children_from_xml(self, element: ET._Element):
for _ in element:
Expand Down Expand Up @@ -350,66 +330,6 @@ def from_xml(cls, element: ET._Element, strict: bool = False) -> "Time":
return datatype


@deprecate_type
@register_type("email")
class Email(ScalarType):
"""Element tag: `<email>`"""

tag = "email"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
deprecate_type(type(self))

def get_example(self):
return "hello@example.com"


@deprecate_type
@register_type("url")
class URL(ScalarType):
"""Element tag: `<url>`"""

tag = "url"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
deprecate_type(type(self))

def get_example(self):
return "https://example.com"


@deprecate_type
@register_type("pythoncode")
class PythonCode(ScalarType):
"""Element tag: `<pythoncode>`"""

tag = "pythoncode"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
deprecate_type(type(self))

def get_example(self):
return "print('hello world')"


@deprecate_type
@register_type("sql")
class SQLCode(ScalarType):
"""Element tag: `<sql>`"""

tag = "sql"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
deprecate_type(type(self))

def get_example(self):
return "SELECT * FROM table"


@register_type("percentage")
class Percentage(ScalarType):
"""Element tag: `<percentage>`"""
Expand Down Expand Up @@ -507,7 +427,7 @@ def set_children_from_xml(self, element: ET._Element):
# The child must be the datatype that all items in the list
# must conform to.
raise ValueError("List data type must have exactly one child.")
child_data_type_tag = update_deprecated_type_to_string(child.tag)
child_data_type_tag = child.tag
child_data_type = registry[child_data_type_tag]
self._children["item"] = child_data_type.from_xml(child)

Expand Down
27 changes: 1 addition & 26 deletions guardrails/utils/json_utils.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
import json
import warnings
from dataclasses import dataclass
from typing import Any, Dict, Optional, Tuple, Type, Union

import regex

from guardrails.datatypes import (
URL,
Boolean,
Case,
Choice,
DataType,
Date,
Email,
Enum,
Float,
Integer,
)
from guardrails.datatypes import List as ListDataType
from guardrails.datatypes import (
Object,
PythonCode,
String,
Time,
deprecated_string_types,
)
from guardrails.datatypes import Object, String, Time
from guardrails.utils.parsing_utils import get_code_block, has_code_block


Expand Down Expand Up @@ -56,21 +47,13 @@ def verify(
Enum: str,
}

ignore_types = [
Email, # email and url should become string validators
URL,
PythonCode,
]


@dataclass
class ValuePlaceholder(Placeholder):
datatype_type: Type[DataType]

@property
def type_object(self):
if self.datatype_type in ignore_types:
return Any
return type_map[self.datatype_type]

class VerificationFailed:
Expand Down Expand Up @@ -327,14 +310,6 @@ def _recurse_schema(schema: DataType):
)
else:
datatype_type = type(schema)
if schema.tag in deprecated_string_types:
datatype_type = String
warnings.warn(
f"""The '{schema.tag}' type is deprecated. Use the \
string type instead. Support for this type will \
be dropped in version 0.3.0 and beyond.""",
DeprecationWarning,
)

return ValuePlaceholder(
datatype_type=datatype_type,
Expand Down
11 changes: 1 addition & 10 deletions guardrails/utils/pydantic_utils/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
from enum import Enum
from typing import Any, Callable, Dict, List, Optional, Type, TypeVar, Union, get_args

from pydantic import BaseModel, ConfigDict, HttpUrl, field_validator
from pydantic import BaseModel, ConfigDict, field_validator
from pydantic.fields import FieldInfo

from guardrails.datatypes import URL as URLDataType
from guardrails.datatypes import Boolean as BooleanDataType
from guardrails.datatypes import Case as CaseDataType
from guardrails.datatypes import Choice
Expand All @@ -20,7 +19,6 @@
from guardrails.datatypes import Integer as IntegerDataType
from guardrails.datatypes import List as ListDataType
from guardrails.datatypes import Object as ObjectDataType
from guardrails.datatypes import PythonCode as PythonCodeDataType
from guardrails.datatypes import String as StringDataType
from guardrails.datatypes import Time as TimeDataType
from guardrails.validator_base import Validator
Expand Down Expand Up @@ -284,9 +282,6 @@ def field_to_datatype(field: Union[FieldInfo, Type]) -> Type[DataType]:
# Get the type annotation from the type_annotation
type_annotation = prepare_type_annotation(field)

# Use inline import to avoid circular dependency
from guardrails.datatypes import PythonCode

# Map the type annotation to the corresponding field type
if is_list(type_annotation):
return ListDataType
Expand All @@ -306,12 +301,8 @@ def field_to_datatype(field: Union[FieldInfo, Type]) -> Type[DataType]:
return StringDataType
elif type_annotation == time:
return TimeDataType
elif type_annotation == HttpUrl:
return URLDataType
elif typing.get_origin(type_annotation) == Union:
return ChoiceDataType
elif type_annotation == PythonCode:
return PythonCodeDataType
else:
raise ValueError(f"Unsupported type: {type_annotation}")

Expand Down
6 changes: 0 additions & 6 deletions tests/integration_tests/test_assets/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ def fixture_rail_spec():
<integer name="dummy_integer" description="Any dummy integer" />
<float name="dummy_float" description="Any dummy float" />
<bool name="dummy_boolean" description="Any dummy boolean" />
<email name="dummy_email" description="Any dummy email" />
<url name="dummy_url" description="Any dummy url" />
<date name="dummy_date" description="Any dummy date" />
<time name="dummy_time" description="Any dummy time" />
<list name="dummy_list" description="Any dummy list" />
Expand Down Expand Up @@ -40,8 +38,6 @@ def fixture_llm_output():
"dummy_integer": 42,
"dummy_float": 3.14,
"dummy_boolean": true,
"dummy_email": "example@example.com",
"dummy_url": "https://www.example.com",
"dummy_date": "2020-01-01",
"dummy_time": "12:00:00",
"dummy_list": ["item1", "item2", "item3"],
Expand All @@ -60,8 +56,6 @@ def fixture_validated_output():
"dummy_integer": 42,
"dummy_float": 3.14,
"dummy_boolean": True,
"dummy_email": "example@example.com",
"dummy_url": "https://www.example.com",
"dummy_date": "2020-01-01",
"dummy_time": "12:00:00",
"dummy_list": ["item1", "item2", "item3"],
Expand Down
49 changes: 0 additions & 49 deletions tests/integration_tests/test_validator_type_deprecation.py

This file was deleted.