-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix langchain error (ENG-1236) (#563)
- Loading branch information
Showing
4 changed files
with
54 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import typing as t | ||
|
||
import pydantic | ||
import pydantic.v1.error_wrappers | ||
|
||
|
||
def parse_pydantic_error( | ||
e: t.Union[pydantic.ValidationError, pydantic.v1.error_wrappers.ValidationError] | ||
) -> str: | ||
"""Parse pydantic validation error.""" | ||
message = "Invalid request data provided" | ||
missing = [] | ||
others = [""] | ||
for error in e.errors(): | ||
param = ".".join(map(str, error["loc"])) | ||
if error["type"] == "missing": | ||
missing.append(param) | ||
continue | ||
others.append(error["msg"] + f" on parameter `{param}`") | ||
if len(missing) > 0: | ||
message += f"\n- Following fields are missing: {set(missing)}" | ||
message += "\n- ".join(others) | ||
return message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters