@@ -206,20 +206,15 @@ def create_namespace_entity(namespace_id: str, req: EntityCreateRequest) -> dict
206206 logger .error (f"Guideline validation failed: { e } " )
207207 raise HTTPException (status_code = 422 , detail = f"Invalid guideline metadata schema: { e } " )
208208
209- elif req .type == "policy" :
209+ from kaizen .schema .policy import Policy , PolicyType
210+
210211 try :
211- from kaizen .schema .policy import Policy # type: ignore[import-not-found]
212-
213- try :
214- # The Policy model checks the full payload
215- policy_meta = {k : v for k , v in req .metadata .items () if k not in ("content" , "type" )}
216- Policy (content = req .content , type = req .type , ** policy_meta )
217- except Exception as e :
218- logger .error (f"Policy validation failed: { e } " )
219- raise HTTPException (status_code = 422 , detail = f"Invalid policy metadata schema: { e } " )
220- except ImportError :
221- # Fallback if we're on a branch where kaizen.schema.policy doesn't exist yet
222- logger .warning ("Policy schema missing. Skipping strict validation." )
212+ # The Policy model checks the full payload
213+ policy_meta = {k : v for k , v in req .metadata .items () if k not in ("content" , "type" )}
214+ Policy (content = req .content , type = PolicyType (req .type ), ** policy_meta )
215+ except Exception as e :
216+ logger .error (f"Policy validation failed: { e } " )
217+ raise HTTPException (status_code = 422 , detail = f"Invalid policy metadata schema: { e } " )
223218
224219 client = get_client ()
225220 try :
0 commit comments