MCPcopy Create free account
hub / github.com/ScrapeGraphAI/scrapecraft / define_schema

Function define_schema

backend/app/agents/tools.py:79–105  ·  view source on GitHub ↗

Define the extraction schema for scraping.

(schema_fields: List[Dict[str, str]])

Source from the content-addressed store, hash-verified

77
78@tool
79def define_schema(schema_fields: List[Dict[str, str]]) -> Dict[str, Any]:
80 """Define the extraction schema for scraping."""
81 try:
82 schema_dict = {}
83 for field in schema_fields:
84 field_type = field.get('type', 'str')
85 if field_type == 'str':
86 schema_dict[field['name']] = str
87 elif field_type == 'int':
88 schema_dict[field['name']] = int
89 elif field_type == 'float':
90 schema_dict[field['name']] = float
91 elif field_type == 'bool':
92 schema_dict[field['name']] = bool
93 elif field_type == 'list':
94 schema_dict[field['name']] = list
95 else:
96 schema_dict[field['name']] = str
97
98 return {
99 "success": True,
100 "schema": schema_dict,
101 "fields": schema_fields,
102 "message": f"Schema defined with {len(schema_fields)} fields"
103 }
104 except Exception as e:
105 return {"success": False, "error": str(e)}
106
107@tool
108def generate_code(urls: List[str], extraction_schema: Dict[str, Any]) -> Dict[str, Any]:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected