You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In particular, if a newline is generated after the array's opening [, lm-format-enforcer will not allow the list to be closed with a ]. It appears that:
When the [ character is parsed, a UnionParser is added to the stack with a StringParsingState and a ForceStopParser
When the newline character is parsed, the UnionParser decides that only StringParsingState can accept newlines, and therefore dissolves itself, returning only the StringParsingState onto the stack and removing the ForceStopParser
Without ForceStopParser on the stack, JsonSchemaParser's allowedCharacters implementation does not evaluate any parsers on the stack above StringParsingState, because StringParsingState returns False for canEnd()
Therefore, allowedCharacters does not include ] and the list cannot be closed
This can be verified by adding this test to test_jsonschemaparser.py:
def test_empty_list_with_newline():
class EmptyListOKModel(BaseModel):
num: int
list_of_strings: Optional[List[str]] = Field(None, min_length=0, max_length=1)
no_strings = '{"num":1,"list_of_strings":[\n]}'
_test_json_schema_parsing_with_string(no_strings, EmptyListOKModel.model_json_schema(), True)
I'm not sure what the best solution here is, but some ideas I have are:
Have ForceStopParser allow newlines/whitespace
Prevent UnionParser from dissolving itself if one of its parsers is a ForceStopParser
Any input on what solution would be most idiomatic would be greatly appreciated.
The text was updated successfully, but these errors were encountered:
Thanks for your awesome work on this project!
I'm seeing an issue with JSON like the following:
In particular, if a newline is generated after the array's opening
[
,lm-format-enforcer
will not allow the list to be closed with a]
. It appears that:[
character is parsed, aUnionParser
is added to the stack with aStringParsingState
and aForceStopParser
UnionParser
decides that onlyStringParsingState
can accept newlines, and therefore dissolves itself, returning only theStringParsingState
onto the stack and removing theForceStopParser
ForceStopParser
on the stack,JsonSchemaParser
'sallowedCharacters
implementation does not evaluate any parsers on the stack aboveStringParsingState
, becauseStringParsingState
returnsFalse
forcanEnd()
allowedCharacters
does not include]
and the list cannot be closedThis can be verified by adding this test to
test_jsonschemaparser.py
:I'm not sure what the best solution here is, but some ideas I have are:
ForceStopParser
allow newlines/whitespaceUnionParser
from dissolving itself if one of its parsers is aForceStopParser
Any input on what solution would be most idiomatic would be greatly appreciated.
The text was updated successfully, but these errors were encountered: