Skip to content

Commit e4a2d24

Browse files
committed
add docs to message about prompt failures
1 parent 9b7cfc3 commit e4a2d24

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

guardrails/classes/llm/prompt_callable.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
from guardrails.classes.llm.llm_response import LLMResponse
22

33

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+
410
class PromptCallableException(Exception):
511
pass
612

@@ -29,17 +35,11 @@ def __call__(self, *args, **kwargs) -> LLMResponse:
2935
except Exception as e:
3036
raise PromptCallableException(
3137
"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}"
3639
)
3740
if not isinstance(result, LLMResponse):
3841
raise PromptCallableException(
3942
"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}"
4444
)
4545
return result

guardrails/llm_providers.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from guardrails.errors import UserFacingException
2323
from guardrails.classes.llm.llm_response import LLMResponse
2424
from guardrails.classes.llm.prompt_callable import (
25+
CALLABLE_FAILURE_SUFFIX,
2526
PromptCallableBase,
2627
PromptCallableException,
2728
)
@@ -903,18 +904,12 @@ async def __call__(self, *args, **kwargs) -> LLMResponse:
903904
except Exception as e:
904905
raise PromptCallableException(
905906
"The callable `fn` passed to `Guard(fn, ...)` failed"
906-
f" with the following error: `{e}`. "
907-
"Make sure that `fn` can be called as a function that"
908-
" takes in a single prompt string "
909-
"and returns a string."
907+
f" with the following error: `{e}`. {CALLABLE_FAILURE_SUFFIX}"
910908
)
911909
if not isinstance(result, LLMResponse):
912910
raise PromptCallableException(
913911
"The callable `fn` passed to `Guard(fn, ...)` returned"
914-
f" a non-string value: {result}. "
915-
"Make sure that `fn` can be called as a function that"
916-
" takes in a single prompt string "
917-
"and returns a string."
912+
f" a non-string value: {result}. {CALLABLE_FAILURE_SUFFIX}"
918913
)
919914
return result
920915

0 commit comments

Comments
 (0)