diff --git a/guardrails/classes/llm/prompt_callable.py b/guardrails/classes/llm/prompt_callable.py index 634397489..abc324f20 100644 --- a/guardrails/classes/llm/prompt_callable.py +++ b/guardrails/classes/llm/prompt_callable.py @@ -1,6 +1,12 @@ from guardrails.classes.llm.llm_response import LLMResponse +CALLABLE_FAILURE_SUFFIX = """Make sure that `fn` can be called as a function +that accepts a prompt string, **kwargs, and returns a string. + If you're using a custom LLM callable, please see docs + here: https://go.guardrailsai.com/B1igEy3""" # noqa + + class PromptCallableException(Exception): pass @@ -29,17 +35,11 @@ def __call__(self, *args, **kwargs) -> LLMResponse: except Exception as e: raise PromptCallableException( "The callable `fn` passed to `Guard(fn, ...)` failed" - f" with the following error: `{e}`. " - "Make sure that `fn` can be called as a function that" - " takes in a single prompt string " - "and returns a string." + f" with the following error: `{e}`. {CALLABLE_FAILURE_SUFFIX}" ) if not isinstance(result, LLMResponse): raise PromptCallableException( "The callable `fn` passed to `Guard(fn, ...)` returned" - f" a non-string value: {result}. " - "Make sure that `fn` can be called as a function that" - " takes in a single prompt string " - "and returns a string." + f" a non-string value: {result}. {CALLABLE_FAILURE_SUFFIX}" ) return result diff --git a/guardrails/llm_providers.py b/guardrails/llm_providers.py index be71a62ec..bbe3e21a1 100644 --- a/guardrails/llm_providers.py +++ b/guardrails/llm_providers.py @@ -22,6 +22,7 @@ from guardrails.errors import UserFacingException from guardrails.classes.llm.llm_response import LLMResponse from guardrails.classes.llm.prompt_callable import ( + CALLABLE_FAILURE_SUFFIX, PromptCallableBase, PromptCallableException, ) @@ -903,18 +904,12 @@ async def __call__(self, *args, **kwargs) -> LLMResponse: except Exception as e: raise PromptCallableException( "The callable `fn` passed to `Guard(fn, ...)` failed" - f" with the following error: `{e}`. " - "Make sure that `fn` can be called as a function that" - " takes in a single prompt string " - "and returns a string." + f" with the following error: `{e}`. {CALLABLE_FAILURE_SUFFIX}" ) if not isinstance(result, LLMResponse): raise PromptCallableException( "The callable `fn` passed to `Guard(fn, ...)` returned" - f" a non-string value: {result}. " - "Make sure that `fn` can be called as a function that" - " takes in a single prompt string " - "and returns a string." + f" a non-string value: {result}. {CALLABLE_FAILURE_SUFFIX}" ) return result