langchain icon indicating copy to clipboard operation
langchain copied to clipboard

improve error messages for missing keys in pydantic classes

Open hwchase17 opened this issue 2 years ago • 1 comments

Currently is as below, which is way too ugly

    335 Create a new model by parsing and validating input data from keyword arguments.
    336 
    337 Raises ValidationError if the input data cannot be parsed to form a valid model.
    338 """
    339 # Uses something other than `self` the first arg to allow "self" as a settable attribute
--> 340 values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
    341 if validation_error:
    342     raise validation_error
...
---> 53     input_variables = values["input_variables"]
     54     template = values["template"]
     55     template_format = values["template_format"]

KeyError: 'input_variables'

hwchase17 avatar Nov 10 '22 05:11 hwchase17

Possibly of interest: https://www.willmcgugan.com/blog/tech/post/better-python-tracebacks-with-rich/

delip avatar Nov 15 '22 22:11 delip

Similarly, if you try to do chain.predict(abc='hello') when the chain expects input to be xyz, the ValueError is a bit vague: ValueError: Missing some input keys: {'abc'}

Something like ValueError: Chain requires input parameters ['xyz']. Received ['abc']. would be more helpful

codeananda avatar Jul 05 '23 14:07 codeananda

Hi, @hwchase17! I'm Dosu, and I'm here to help the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, the issue is about improving the error message for missing keys in pydantic classes. There have been some suggestions from other users, such as using the traceback library to provide better error messages and improving the ValueError message to give more helpful information about the missing input parameters. However, it seems that the issue is still unresolved.

Could you please let us know if this issue is still relevant to the latest version of the LangChain repository? If it is, please comment on the issue to let us know. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.

Thank you for your understanding and contribution to the LangChain project!

dosubot[bot] avatar Oct 05 '23 16:10 dosubot[bot]