Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions guardrails/classes/llm/prompt_callable.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
11 changes: 3 additions & 8 deletions guardrails/llm_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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

Expand Down
Loading