diff --git a/adala/runtimes/_litellm.py b/adala/runtimes/_litellm.py index bd2a191b..0cb49ae8 100644 --- a/adala/runtimes/_litellm.py +++ b/adala/runtimes/_litellm.py @@ -306,7 +306,9 @@ def record_to_record( ) # Catch case where the model does not return a properly formatted output - if type(e).__name__ == "ValidationError" and "Invalid JSON" in str(e): + # AttributeError is an instructor bug: https://github.com/instructor-ai/instructor/pull/1103 + # > AttributeError: 'NoneType' object has no attribute '_raw_response' + if type(e).__name__ in {"ValidationError", "AttributeError"}: e = ConstrainedGenerationError() # there are no other known errors to catch dct = _log_llm_exception(e) @@ -464,7 +466,13 @@ async def batch_to_batch( ) # Catch case where the model does not return a properly formatted output - if type(e).__name__ == "ValidationError" and "Invalid JSON" in str(e): + # AttributeError is an instructor bug: https://github.com/instructor-ai/instructor/pull/1103 + # > AttributeError: 'NoneType' object has no attribute '_raw_response' + if type(e).__name__ in {"ValidationError", "AttributeError"}: + logger.error( + f"Converting error to ConstrainedGenerationError: {str(e)}" + ) + logger.debug(f"Traceback:\n{traceback.format_exc()}") e = ConstrainedGenerationError() # the only other instructor error that would be thrown is IncompleteOutputException due to max_tokens reached dct = _log_llm_exception(e)