diff --git a/guardrails/run.py b/guardrails/run.py index 0d133e4c4..0509563b0 100644 --- a/guardrails/run.py +++ b/guardrails/run.py @@ -1380,13 +1380,15 @@ def parse( output, stream=True, verified=verified ) - # Error can be either of (True/False/None/string representing error) + # Error can be either of + # (True/False/None/ValueError/string representing error) if error: # If parsing error is a string, # it is an error from output_schema.parse_fragment() if isinstance(error, str): raise ValueError("Unable to parse output: " + error) - # Else if either of (None/True/False), return parsed_output and error + # Else if either of + # (None/True/False/ValueError), return parsed_output and error action.log( message_type="info", diff --git a/guardrails/schema/string_schema.py b/guardrails/schema/string_schema.py index a90b6cc62..cde8a8b0f 100644 --- a/guardrails/schema/string_schema.py +++ b/guardrails/schema/string_schema.py @@ -123,7 +123,9 @@ def get_reask_setup( return self, prompt, instructions def parse(self, output: str, **kwargs) -> Tuple[Any, Optional[Exception]]: - return output, None + # Return a ValueError if the output is empty, else None + error = ValueError("Empty response received.") if not output else None + return output, error def validate( self,