diff --git a/guardrails/applications/text2sql.rail b/guardrails/applications/text2sql.rail index 27732b5df..631d61864 100644 --- a/guardrails/applications/text2sql.rail +++ b/guardrails/applications/text2sql.rail @@ -1,6 +1,6 @@ - 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: @@ -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: ``""" - - 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: ``""" - - 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: ``""" - - 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: ``""" - - 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: ``""" @@ -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) diff --git a/guardrails/utils/json_utils.py b/guardrails/utils/json_utils.py index 65c1e1442..90d09b141 100644 --- a/guardrails/utils/json_utils.py +++ b/guardrails/utils/json_utils.py @@ -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 @@ -56,12 +47,6 @@ def verify( Enum: str, } -ignore_types = [ - Email, # email and url should become string validators - URL, - PythonCode, -] - @dataclass class ValuePlaceholder(Placeholder): @@ -69,8 +54,6 @@ class ValuePlaceholder(Placeholder): @property def type_object(self): - if self.datatype_type in ignore_types: - return Any return type_map[self.datatype_type] class VerificationFailed: @@ -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, diff --git a/guardrails/utils/pydantic_utils/v2.py b/guardrails/utils/pydantic_utils/v2.py index 566086259..141d0d764 100644 --- a/guardrails/utils/pydantic_utils/v2.py +++ b/guardrails/utils/pydantic_utils/v2.py @@ -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 @@ -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 @@ -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 @@ -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}") diff --git a/tests/integration_tests/test_assets/fixtures/__init__.py b/tests/integration_tests/test_assets/fixtures/__init__.py index 6b08e8913..65d72c190 100644 --- a/tests/integration_tests/test_assets/fixtures/__init__.py +++ b/tests/integration_tests/test_assets/fixtures/__init__.py @@ -11,8 +11,6 @@ def fixture_rail_spec(): - -