|
1 | 1 | from guardrails.classes.llm.llm_response import LLMResponse |
2 | 2 |
|
3 | 3 |
|
| 4 | +CALLABLE_FAILURE_SUFFIX = """Make sure that `fn` can be called as a function |
| 5 | +that accepts a prompt string, **kwargs, and returns a string. |
| 6 | + If you're using a custom LLM callable, please see docs |
| 7 | + here: https://go.guardrailsai.com/B1igEy3""" # noqa |
| 8 | + |
| 9 | + |
4 | 10 | class PromptCallableException(Exception): |
5 | 11 | pass |
6 | 12 |
|
@@ -29,17 +35,11 @@ def __call__(self, *args, **kwargs) -> LLMResponse: |
29 | 35 | except Exception as e: |
30 | 36 | raise PromptCallableException( |
31 | 37 | "The callable `fn` passed to `Guard(fn, ...)` failed" |
32 | | - f" with the following error: `{e}`. " |
33 | | - "Make sure that `fn` can be called as a function that" |
34 | | - " takes in a single prompt string " |
35 | | - "and returns a string." |
| 38 | + f" with the following error: `{e}`. {CALLABLE_FAILURE_SUFFIX}" |
36 | 39 | ) |
37 | 40 | if not isinstance(result, LLMResponse): |
38 | 41 | raise PromptCallableException( |
39 | 42 | "The callable `fn` passed to `Guard(fn, ...)` returned" |
40 | | - f" a non-string value: {result}. " |
41 | | - "Make sure that `fn` can be called as a function that" |
42 | | - " takes in a single prompt string " |
43 | | - "and returns a string." |
| 43 | + f" a non-string value: {result}. {CALLABLE_FAILURE_SUFFIX}" |
44 | 44 | ) |
45 | 45 | return result |
0 commit comments