@@ -619,6 +619,19 @@ def to_dict(self) -> Dict[str, Any]:
619619 """Convert configuration to a dictionary."""
620620 return self .model_dump (mode = "json" )
621621
622+ @classmethod
623+ def _normalize_config_for_io (cls , config_dict : Dict [str , Any ]) -> Dict [str , Any ]:
624+ """Normalize config payload before save/load validation.
625+
626+ Enforces strict IO requirements so save/load behavior is consistent:
627+ ``fit_routines`` must be present and non-empty.
628+ """
629+ normalized = dict (config_dict or {})
630+ fit_routines = normalized .get ("fit_routines" )
631+ if not fit_routines :
632+ raise ValueError ("fit_routines must be defined in the config file" )
633+ return normalized
634+
622635 def save (self , path : Optional [Path ] = None ) -> Path :
623636 """
624637 Save configuration to a YAML file.
@@ -635,9 +648,11 @@ def save(self, path: Optional[Path] = None) -> Path:
635648 # Ensure directory exists
636649 path .parent .mkdir (parents = True , exist_ok = True )
637650
651+ normalized = self ._normalize_config_for_io (self .to_dict ())
652+
638653 # Save config as YAML
639654 with open (path , "w" ) as f :
640- yaml .safe_dump (self . to_dict () , f , sort_keys = False )
655+ yaml .safe_dump (normalized , f , sort_keys = False )
641656
642657 return path
643658
@@ -669,7 +684,8 @@ def load(cls, path: Optional[Path] = None) -> "PleiadesConfig":
669684 @classmethod
670685 def from_dict (cls , config_dict : Dict [str , Any ]) -> "PleiadesConfig" :
671686 """Build a configuration from a dictionary."""
672- return cls .model_validate (config_dict or {}, context = {"require_fit_routines" : True })
687+ normalized = cls ._normalize_config_for_io (config_dict )
688+ return cls .model_validate (normalized , context = {"require_fit_routines" : True })
673689
674690
675691class IsotopeConfig (BaseModel ):
0 commit comments