Skip to content

Commit

Permalink
fix bad merge in code originally from validators.py (#427)
Browse files Browse the repository at this point in the history
* fix bad merge in code originally from validators.py

* lint fixes
  • Loading branch information
CalebCourier authored Nov 3, 2023
1 parent 24285ab commit cb3e93a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 8 additions & 4 deletions guardrails/validator_base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
from collections import defaultdict
from typing import Any, Callable, Dict, List, Literal, Optional, Type, Union

Expand Down Expand Up @@ -245,11 +246,14 @@ def to_xml_attrib(self):
return self.rail_alias

validator_args = []
for arg in self.__init__.__code__.co_varnames[1:]:
init_args = inspect.getfullargspec(self.__init__)
for arg in init_args.args[1:]:
if arg not in ("on_fail", "args", "kwargs"):
str_arg = str(self._kwargs[arg])
str_arg = "{" + str_arg + "}" if " " in str_arg else str_arg
validator_args.append(str_arg)
arg_value = self._kwargs.get(arg)
str_arg = str(arg_value)
if str_arg is not None:
str_arg = "{" + str_arg + "}" if " " in str_arg else str_arg
validator_args.append(str_arg)

params = " ".join(validator_args)
return f"{self.rail_alias}: {params}"
Expand Down
5 changes: 3 additions & 2 deletions guardrails/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import rstr
from tenacity import retry, stop_after_attempt, wait_random_exponential

from guardrails.utils.casting_utils import to_int
from guardrails.utils.docs_utils import get_chunks_from_text, sentence_split
from guardrails.utils.sql_utils import SQLDriver, create_sql_driver
from guardrails.utils.validator_utils import PROVENANCE_V1_PROMPT
Expand Down Expand Up @@ -277,8 +278,8 @@ def __init__(
on_fail: Optional[Callable] = None,
):
super().__init__(on_fail=on_fail, min=min, max=max)
self._min = int(min) if min is not None else None
self._max = int(max) if max is not None else None
self._min = to_int(min)
self._max = to_int(max)

def validate(self, value: Union[str, List], metadata: Dict) -> ValidationResult:
"""Validates that the length of value is within the expected range."""
Expand Down

0 comments on commit cb3e93a

Please sign in to comment.