Skip to content

Commit

Permalink
Fix JSON schema generation to accept schemas without 'title' property
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkindy committed Oct 3, 2023
1 parent 4ce76ff commit 81c4c12
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion outlines/text/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def expand_json_schema(
expanded_properties[name] = value

return {
"title": raw_schema["title"],
**({"title": raw_schema["title"]} if "title" in raw_schema else {}),
"type": raw_schema["type"],
"properties": expanded_properties,
}
Expand Down
12 changes: 12 additions & 0 deletions tests/text/test_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ def test_json_schema():
]


def test_json_schema_no_titles():
schema = '{"type": "object", "properties": {"user_id": {"type": "integer"}, "name": {"type": "string"}}, "required": ["user_id", "name"]}'
schedule = build_schedule_from_schema(schema)
assert schedule == [
'\\{[\\n ]*"user_id"[\\n ]*:[\\n ]*',
{"type": "integer"},
'[\\n ]*,[\\n ]*"name"[\\n ]*:[\\n ]*',
{"type": "string"},
"[\\n ]*\\}",
]


def test_json_schema_with_property_ref():
schema = """{
"title": "User",
Expand Down

0 comments on commit 81c4c12

Please sign in to comment.