Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion crawl4ai/extraction_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,15 @@ def generate_schema(
)

# Extract and return schema
return json.loads(response.choices[0].message.content)
# Clean markdown code blocks that LLMs sometimes wrap JSON in
content = response.choices[0].message.content
# Remove markdown code block markers if present
if "```json" in content:
content = content.replace("```json\n", "").replace("\n```", "")
elif "```" in content:
content = content.replace("```\n", "").replace("\n```", "")
content = content.strip()
return json.loads(content)

except Exception as e:
raise Exception(f"Failed to generate schema: {str(e)}")
Expand Down