Skip to content

Commit 122861f

Browse files
committed
fix(ai): force schema array to always be present to prevent Groq tool use failure
1 parent 9cba4f0 commit 122861f

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

  • apps/python-service/routers

‎apps/python-service/routers/ai.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ class CollectionCreatorRequest(BaseModel):
5959
class CollectionCreatorResponse(BaseModel):
6060
type: Literal["clarify", "schema", "complete"]
6161
message: str
62-
schema_: list[CollectionSchema] | None = Field(default=None, alias="schema")
62+
schema_: list[CollectionSchema] = Field(..., alias="schema", description="Must be an empty array [] if type is 'clarify'")
6363

6464
model_config = ConfigDict(populate_by_name=True)
6565

6666
@model_validator(mode='after')
6767
def check_schema_presence(self):
68-
if self.type == "schema" and self.schema_ is None:
69-
raise ValueError("schema_ must be provided when type is 'schema'")
68+
if self.type == "schema" and not self.schema_:
69+
raise ValueError("schema_ must not be empty when type is 'schema'")
7070
return self
7171

7272
@router.post("/query-builder", response_model=QueryResult)
@@ -169,7 +169,7 @@ async def collection_creator(request: CollectionCreatorRequest, req: Request):
169169
system_prompt = """You are a MongoDB schema designer for urBackend, a Backend-as-a-Service platform.
170170
171171
Rules:
172-
1. If the description is vague, ask 2-3 specific clarifying questions and set type: "clarify". NEVER ask more than 3 at once.
172+
1. If the description is vague, ask 2-3 specific clarifying questions and set type: "clarify". Set schema: [] to satisfy the tool schema. NEVER ask more than 3 at once.
173173
2. Once you have enough context, propose a schema and set type: "schema".
174174
3. Only use these field types: String, Number, Boolean, Date, Object, Array, Ref.
175175
4. ALWAYS include "createdAt" (type: Date, required: true) in EVERY collection.

0 commit comments

Comments
 (0)