Hello, thanks for offering to help!
Here is a script with schema that throws the error.
import requests
import json
API_KEY = "XYZ"
API_URL = "https://generativelanguage.googleapis.com/v1beta/openai/v1/chat/completions"
MODEL = "gemini-2.5-flash"
schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "User Profiles List",
"type": "object",
"properties": {
"profiles": {
"type": "array",
"maxItems": 3,
"items": {
"type": "object",
"properties": {
"id": {"type": "integer", "minimum": 1},
"name": {"type": "string", "minLength": 1},
"email": {"type": "string", "format": "email"},
"address": {
"type": "object",
"properties": {
"street": {"type": "string"},
"city": {"type": "string"},
"country": {"type": "string", "default": "USA"},
"coordinates": {
"type": "object",
"properties": {
"latitude": {
"type": "number",
"minimum": -90,
"maximum": 90,
},
"longitude": {
"type": "number",
"minimum": -180,
"maximum": 180,
},
},
"required": ["latitude", "longitude"],
},
},
"required": ["street", "city", "coordinates"],
},
"preferences": {
"type": "object",
"properties": {
"theme": {
"type": "string",
"enum": ["light", "dark", "auto"],
},
"notifications": {
"type": "object",
"properties": {
"email": {"type": "boolean"},
"push": {"type": "boolean"},
"sms": {"type": "boolean"},
},
"required": ["email", "push"],
},
},
"required": ["theme", "notifications"],
},
},
"required": ["id", "name", "email", "address", "preferences"],
},
}
},
"required": ["profiles"],
}
payload = {
"model": MODEL,
"messages": [
{"role": "user", "content": "Generate a list of 1 to 3 user profiles."}
],
"response_format": {
"type": "json_schema",
"json_schema": {"name": "user_profiles_list", "strict": True, "schema": schema},
},
}
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {API_KEY}"}
response = requests.post(API_URL, headers=headers, json=payload)
data = response.json()
print("RAW DATA", data)
json_output = data["choices"][0]["message"]["content"]
print(json.dumps(json.loads(json_output), indent=2))
And on running:
RAW DATA [{'error': {'code': 400, 'message': 'A schema in GenerationConfig in the request exceeds the maximum allowed nesting depth.', 'status': 'INVALID_ARGUMENT'}}]
Traceback (most recent call last):
File "/x/y/z/test_json.py", line 90, in <module>
json_output = data["choices"][0]["message"]["content"]
~~~~^^^^^^^^^^^
TypeError: list indices must be integers or slices, not str