{
"event": "PreToolUse",
"tool_name": "Read",
"tool_input": {
"file_path": "\/var\/www\/scripts\/pipeline\/analyzers\/entity_extractor.py",
"offset": 160,
"limit": 60
}
}
{
"tool_response": {
"type": "text",
"file": {
"filePath": "\/var\/www\/scripts\/pipeline\/analyzers\/entity_extractor.py",
"content": " request=f\"[entity_extraction] {prompt[:500]}...\",\n model_name=ANTHROPIC_MODEL,\n status=\"error\",\n error_message=str(e),\n )\n return []\n\n\ndef store_entities(document_id: int, entities: list[dict]) -> int:\n \"\"\"Store extracted entities in database.\"\"\"\n stored = 0\n\n for entity in entities:\n try:\n description = entity.get(\"description\") or entity.get(\"context\") or None\n\n cursor = db.execute(\n \"SELECT id, description FROM entities WHERE name = %s AND type = %s\", (entity[\"name\"], entity[\"type\"])\n )\n existing = cursor.fetchone()\n cursor.close()\n\n if existing:\n entity_id = existing[\"id\"]\n if description and not existing[\"description\"]:\n cursor = db.execute(\"UPDATE entities SET description = %s WHERE id = %s\", (description, entity_id))\n db.commit()\n cursor.close()\n else:\n cursor = db.execute(\n \"\"\"INSERT INTO entities (name, type, description, created_at)\n VALUES (%s, %s, %s, NOW())\"\"\",\n (entity[\"name\"], entity[\"type\"], description),\n )\n db.commit()\n entity_id = cursor.lastrowid\n cursor.close()\n\n db.log_provenance(\n artifact_type=\"entity\",\n artifact_id=entity_id,\n source_type=\"extraction\",\n source_id=document_id,\n pipeline_step=\"entity_extract\",\n )\n\n stored += 1\n\n except Exception as e:\n db.log(\"WARNING\", f\"Failed to store entity: {e}\")\n\n return stored\n\n\ndef find_entity_by_name(name: str) -> dict | None:\n \"\"\"Find entity by name or canonical_name.\"\"\"\n name_lower = name.lower().strip()\n canonical = name_lower.replace(\" \", \"\").replace(\"-\", \"\")\n\n cursor = db.execute(",
"numLines": 60,
"startLine": 160,
"totalLines": 244
}
}
}