from __future__ import annotations from typing import Any, Dict, List, Optional, Tuple from .spacy_extractor import VALID_SPACY_LABELS def validate_mappings(fields: Dict[str, Dict[str, Any]]) -> Tuple[bool, Optional[Dict]]: invalid: List[str] = [] for field_name, rule in fields.items(): if rule.get("source_type") == "entity": label = rule.get("label", "") if label not in VALID_SPACY_LABELS: invalid.append(label) if not invalid: return True, None return False, { "invalid_labels": invalid, "valid_labels": VALID_SPACY_LABELS, "suggestion": ( "Use source_type 'regex' for custom patterns not covered by spaCy NER labels." ), }