| 126 | # ── Test 3: Nested schema ──────────────────────────────────────────────── |
| 127 | |
| 128 | def test_nested(): |
| 129 | result = session.tool("generate_object", { |
| 130 | "schema": { |
| 131 | "type": "object", |
| 132 | "required": ["book"], |
| 133 | "properties": { |
| 134 | "book": { |
| 135 | "type": "object", |
| 136 | "required": ["title", "author", "year", "genres"], |
| 137 | "properties": { |
| 138 | "title": {"type": "string"}, |
| 139 | "author": {"type": "string"}, |
| 140 | "year": {"type": "integer", "minimum": 1800, "maximum": 2030}, |
| 141 | "genres": { |
| 142 | "type": "array", |
| 143 | "items": {"type": "string"}, |
| 144 | "minItems": 1, |
| 145 | }, |
| 146 | }, |
| 147 | } |
| 148 | }, |
| 149 | }, |
| 150 | "prompt": 'Extract book info: "1984 by George Orwell, published 1949, genres: dystopian fiction, political fiction"', |
| 151 | "schema_name": "book_info", |
| 152 | }) |
| 153 | assert result.exit_code == 0, f"Tool failed: {result.output}" |
| 154 | parsed = json.loads(result.output) |
| 155 | obj = parsed["object"]["book"] |
| 156 | assert "1984" in obj["title"], f"title: {obj['title']}" |
| 157 | assert "orwell" in obj["author"].lower(), f"author: {obj['author']}" |
| 158 | assert obj["year"] == 1949, f"year: {obj['year']}" |
| 159 | assert len(obj["genres"]) >= 1, f"genres: {obj['genres']}" |
| 160 | print(f" Result: {obj['title']} by {obj['author']} ({obj['year']})") |
| 161 | |
| 162 | run_test("generate_object: nested schema (book)", test_nested) |
| 163 | |