mirror of
				https://github.com/hwchase17/langchain.git
				synced 2025-11-04 10:10:09 +00:00 
			
		
		
		
	Several `core` modules do not have descriptions, like the [agent](https://api.python.langchain.com/en/latest/core_api_reference.html#module-langchain_core.agents) module. - Added missed module descriptions. The descriptions are mostly copied from the `langchain` or `community` package modules.
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
"""Custom **exceptions** for LangChain. """
 | 
						|
from typing import Any, Optional
 | 
						|
 | 
						|
 | 
						|
class LangChainException(Exception):
 | 
						|
    """General LangChain exception."""
 | 
						|
 | 
						|
 | 
						|
class TracerException(LangChainException):
 | 
						|
    """Base class for exceptions in tracers module."""
 | 
						|
 | 
						|
 | 
						|
class OutputParserException(ValueError, LangChainException):
 | 
						|
    """Exception that output parsers should raise to signify a parsing error.
 | 
						|
 | 
						|
    This exists to differentiate parsing errors from other code or execution errors
 | 
						|
    that also may arise inside the output parser. OutputParserExceptions will be
 | 
						|
    available to catch and handle in ways to fix the parsing error, while other
 | 
						|
    errors will be raised.
 | 
						|
 | 
						|
    Args:
 | 
						|
        error: The error that's being re-raised or an error message.
 | 
						|
        observation: String explanation of error which can be passed to a
 | 
						|
            model to try and remediate the issue.
 | 
						|
        llm_output: String model output which is error-ing.
 | 
						|
        send_to_llm: Whether to send the observation and llm_output back to an Agent
 | 
						|
            after an OutputParserException has been raised. This gives the underlying
 | 
						|
            model driving the agent the context that the previous output was improperly
 | 
						|
            structured, in the hopes that it will update the output to the correct
 | 
						|
            format.
 | 
						|
    """
 | 
						|
 | 
						|
    def __init__(
 | 
						|
        self,
 | 
						|
        error: Any,
 | 
						|
        observation: Optional[str] = None,
 | 
						|
        llm_output: Optional[str] = None,
 | 
						|
        send_to_llm: bool = False,
 | 
						|
    ):
 | 
						|
        super(OutputParserException, self).__init__(error)
 | 
						|
        if send_to_llm:
 | 
						|
            if observation is None or llm_output is None:
 | 
						|
                raise ValueError(
 | 
						|
                    "Arguments 'observation' & 'llm_output'"
 | 
						|
                    " are required if 'send_to_llm' is True"
 | 
						|
                )
 | 
						|
        self.observation = observation
 | 
						|
        self.llm_output = llm_output
 | 
						|
        self.send_to_llm = send_to_llm
 |