Skip to content

Commit

Permalink
Add more informative error message when decoding JSON output fails
Browse files Browse the repository at this point in the history
  • Loading branch information
rlouf committed Dec 21, 2023
1 parent 6327421 commit 0693a0d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion outlines/generate/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,16 @@ def __call__(
]

generated = self.tokenizer.decode(token_ids)
formatted = [self.format_sequence(sequence) for sequence in generated]

try:
formatted = [self.format_sequence(sequence) for sequence in generated]
except pyjson.decoder.JSONDecodeError:
raise TypeError(
"Could not format the output of the model into a dictionary or a Pydantic model."
+ " The model has likely exceeded its context length. Please try again using `constr` (for Pydantic)"
+ " and `maxLength` (for JSON Schema) to limit the length of the string fields. If this exception"
+ " is raised nevertheless please open an issue: https://github.com/outlines-dev/outlines/issues"
)

return formatted if len(formatted) > 1 else formatted[0]

Expand Down

0 comments on commit 0693a0d

Please sign in to comment.