diff --git a/sotopia/samplers/constraint_based_sampler.py b/sotopia/samplers/constraint_based_sampler.py index 624520dcd..28f127a20 100644 --- a/sotopia/samplers/constraint_based_sampler.py +++ b/sotopia/samplers/constraint_based_sampler.py @@ -87,10 +87,16 @@ def sample( agents_which_fit_scenario: list[list[str]] = [] if self.env_candidates is None: - self.env_candidates = EnvironmentProfile.all() + env_candidates = EnvironmentProfile.all() + if not env_candidates: + raise ValueError("No environment candidates available for sampling.") + self.env_candidates = env_candidates if self.agent_candidates is None: - self.agent_candidates = AgentProfile.all() + agent_candidates = AgentProfile.all() + if not agent_candidates: + raise ValueError("No agent candidates available for sampling.") + self.agent_candidates = agent_candidates agent_candidate_ids: set[str] | None = None if self.agent_candidates: diff --git a/sotopia/samplers/uniform_sampler.py b/sotopia/samplers/uniform_sampler.py index 22c89f3c3..bfb729f55 100644 --- a/sotopia/samplers/uniform_sampler.py +++ b/sotopia/samplers/uniform_sampler.py @@ -47,10 +47,16 @@ def sample( assert replacement, "Uniform sampling without replacement is not supported yet" if self.env_candidates is None: - self.env_candidates = EnvironmentProfile.all() + env_candidates = EnvironmentProfile.all() + if not env_candidates: + raise ValueError("No environment candidates available for sampling.") + self.env_candidates = env_candidates if self.agent_candidates is None: - self.agent_candidates = AgentProfile.all() + agent_candidates = AgentProfile.all() + if not agent_candidates: + raise ValueError("No agent candidates available for sampling.") + self.agent_candidates = agent_candidates for _ in range(size): env_profile = random.choice(self.env_candidates)