{"record":{"id":"ddf59dcdac3b9c8e","repo":"ScrapeGraphAI/Scrapegraph-ai","slug":"invalid-pydantic-schema-missing-properties-key","errorCode":null,"errorMessage":"Invalid pydantic schema: missing 'properties' key","messagePattern":"Invalid pydantic schema: missing 'properties' key","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scrapegraphai/utils/schema_trasform.py","lineNumber":52,"sourceCode":"                    else:\n                        result[key] = [\"unknown\"]  # fallback for malformed array\n                else:\n                    result[key] = {\n                        \"type\": value[\"type\"],\n                        \"description\": value.get(\"description\", \"\"),\n                    }\n            elif \"$ref\" in value:\n                ref_key = value[\"$ref\"].split(\"/\")[-1]\n                if \"$defs\" in pydantic_schema and ref_key in pydantic_schema[\"$defs\"]:\n                    result[key] = process_properties(\n                        pydantic_schema[\"$defs\"][ref_key].get(\"properties\", {})\n                    )\n                else:\n                    result[key] = {\"type\": \"object\", \"description\": \"Missing reference\"}  # fallback\n        return result\n\n    if \"properties\" not in pydantic_schema:\n        raise ValueError(\"Invalid pydantic schema: missing 'properties' key\")\n    return process_properties(pydantic_schema[\"properties\"])\n","sourceCodeStart":34,"sourceCodeEnd":54,"githubUrl":"https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/532dfffbf6ee823a6c9cf8cfedc24a93bf026780/scrapegraphai/utils/schema_trasform.py#L34-L54","documentation":"Raised by transform_schema when the provided pydantic schema dict does not contain a top-level 'properties' key, meaning it is not a valid JSON-schema-style object schema. The function only knows how to transform object schemas with properties.","triggerScenarios":"Calling transform_schema (used by graph execute paths that build structured output schemas) with a schema like {\"type\": \"string\"}, {\"title\": \"X\"}, or a raw $def-only dict lacking \"properties\".","commonSituations":"Passing a scalar/array output schema instead of an object with fields; passing model_json_schema() of a RootModel or a schema already transformed/trimmed; nesting errors where a subschema is passed instead of the top-level one.","solutions":["Ensure the schema is a pydantic model's JSON schema with at least one field: class Out(BaseModel): x: str -> Out.model_json_schema() has 'properties'","Wrap scalar outputs in a model with a named field","If using RootModel, replace it with a normal model containing fields","Log/inspect the schema dict before calling transform_schema"],"exampleFix":"# before\nclass Out(RootModel[str]): ...  # no 'properties'\ntransform_schema(Out.model_json_schema())\n# after\nclass Out(BaseModel):\n    answer: str\ntransform_schema(Out.model_json_schema())","handlingStrategy":"validation","validationCode":"schema = Out.model_json_schema()\nassert \"properties\" in schema and schema[\"properties\"], \"schema must be an object model with fields\"","typeGuard":"def is_transformable_schema(schema: dict) -> bool:\n    return isinstance(schema, dict) and isinstance(schema.get(\"properties\"), dict) and len(schema[\"properties\"]) > 0","tryCatchPattern":"try:\n    transformed = transform_schema(schema)\nexcept ValueError as e:\n    raise ValueError(f\"output schema invalid: {e}\") from e","preventionTips":["Always derive schemas from pydantic BaseModel subclasses with fields","Never pass scalar/root-model schemas to transform_schema","Add a schema unit test for every output model"],"tags":["schema","pydantic","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"532dfffbf6ee823a6c9cf8cfedc24a93bf026780","analyzedAt":"2026-08-28T15:19:38.821Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}