mirror of
https://github.com/hwchase17/langchain.git
synced 2025-10-10 00:25:14 +00:00
docs, core: error messaging [wip] (#27397)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""Custom **exceptions** for LangChain."""
|
||||
|
||||
from enum import Enum
|
||||
from typing import Any, Optional
|
||||
|
||||
|
||||
@@ -39,6 +40,10 @@ class OutputParserException(ValueError, LangChainException): # noqa: N818
|
||||
llm_output: Optional[str] = None,
|
||||
send_to_llm: bool = False,
|
||||
):
|
||||
if isinstance(error, str):
|
||||
error = create_message(
|
||||
message=error, error_code=ErrorCode.OUTPUT_PARSING_FAILURE
|
||||
)
|
||||
super().__init__(error)
|
||||
if send_to_llm and (observation is None or llm_output is None):
|
||||
msg = (
|
||||
@@ -49,3 +54,21 @@ class OutputParserException(ValueError, LangChainException): # noqa: N818
|
||||
self.observation = observation
|
||||
self.llm_output = llm_output
|
||||
self.send_to_llm = send_to_llm
|
||||
|
||||
|
||||
class ErrorCode(Enum):
|
||||
INVALID_PROMPT_INPUT = "INVALID_PROMPT_INPUT"
|
||||
INVALID_TOOL_RESULTS = "INVALID_TOOL_RESULTS"
|
||||
MESSAGE_COERCION_FAILURE = "MESSAGE_COERCION_FAILURE"
|
||||
MODEL_AUTHENTICATION = "MODEL_AUTHENTICATION"
|
||||
MODEL_NOT_FOUND = "MODEL_NOT_FOUND"
|
||||
MODEL_RATE_LIMIT = "MODEL_RATE_LIMIT"
|
||||
OUTPUT_PARSING_FAILURE = "OUTPUT_PARSING_FAILURE"
|
||||
|
||||
|
||||
def create_message(*, message: str, error_code: ErrorCode) -> str:
|
||||
return (
|
||||
f"{message}\n"
|
||||
"For troubleshooting, visit: https://python.langchain.com/docs/"
|
||||
f"troubleshooting/errors/{error_code.value}"
|
||||
)
|
||||
|
Reference in New Issue
Block a user