Autonomous AI sales agent powered by Claude Code or Codex. Finds prospects, writes cold emails, sends campaigns, handles replies, books meetings. No API keys needed — runs on your Claude or Codex subscriptions.
Reject unquoted YAML booleans for prospect_country; share its validation
Ethan2612be5fceb3
diff --git a/harvey/config.py b/harvey/config.pyindex a57e9b4..5205a1d 100644--- a/harvey/config.py+++ b/harvey/config.py@@ -109,6 +109,27 @@ class ChannelsConfig(BaseModel):PRECLEARED_ADDRESS_SOURCES = ("published", "bought", "scraped", "given", "unknown")+def normalize_prospect_country(v) -> str:+ """A two-letter country code ("us" -> "US", "UK" -> "GB"), or "" for none.++ Raises ValueError on anything else, including the booleans YAML makes of+ an unquoted NO (Norway) or ON, so a typo is never silently ignored.+ """+ if isinstance(v, bool):+ raise ValueError(+ f"prospect_country was read as {v}. YAML turns an unquoted NO or "+ 'ON into true/false, so quote the code, e.g. prospect_country: "NO".'+ )+ v = str(v or "").strip().upper()+ v = {"UK": "GB", "USA": "US"}.get(v, v)+ if v and not (len(v) == 2 and v.isascii() and v.isalpha()):+ raise ValueError(+ f"'{v}' is not a valid prospect_country. Use a two-letter "+ "country code such as US or GB, or leave it empty."+ )+ return v++class PreclearedConfig(BaseModel):"""Optional per-recipient cold-email check through Precleared.@@ -151,14 +172,7 @@ class PreclearedConfig(BaseModel):@field_validator("prospect_country", mode="before")@classmethoddef _valid_prospect_country(cls, v) -> str:- v = str(v or "").strip().upper()- v = {"UK": "GB", "USA": "US"}.get(v, v)- if v and not (len(v) == 2 and v.isascii() and v.isalpha()):- raise ValueError(- f"'{v}' is not a valid prospect_country. Use a two-letter "- "country code such as US or GB, or leave it empty."- )- return v+ return normalize_prospect_country(v)@model_validator(mode="after")def _country_when_enabled(self):diff --git a/harvey/integrations/precleared.py b/harvey/integrations/precleared.pyindex b7c0b84..67283cb 100644--- a/harvey/integrations/precleared.py+++ b/harvey/integrations/precleared.py@@ -39,6 +39,8 @@ from urllib.parse import unquote, urlsplitimport httpx+from harvey.config import normalize_prospect_country+logger = logging.getLogger("harvey.precleared")API_URL = "https://precleared.dev/api/v1/check"@@ -90,7 +92,7 @@ class PreclearedClient:self.api_key = api_key or ""self.address_source = address_sourceself.pitch = (pitch or "").strip()[:200]- self.prospect_country = (prospect_country or "").strip().upper()+ self.prospect_country = normalize_prospect_country(prospect_country)self._transport = transport # tests inject httpx.MockTransport@classmethoddiff --git a/tests/test_precleared.py b/tests/test_precleared.pyindex 76d8033..50d456b 100644--- a/tests/test_precleared.py+++ b/tests/test_precleared.py@@ -150,6 +150,20 @@ def test_prospect_country_is_optional_and_normalised():PreclearedConfig(enabled=True, sender_country="US", prospect_country="United States")[email protected]("yaml_value", [False, True])+def test_unquoted_yaml_country_is_an_error_not_ignored(yaml_value):+ # YAML reads an unquoted NO (Norway) as False and ON as True.+ with pytest.raises(ValidationError, match="quote"):+ PreclearedConfig(enabled=True, sender_country="US", prospect_country=yaml_value)+++def test_client_normalises_prospect_country_like_the_config():+ assert PreclearedClient("US", prospect_country="uk").prospect_country == "GB"+ assert PreclearedClient("US", prospect_country="usa").prospect_country == "US"+ with pytest.raises(ValueError):+ PreclearedClient("US", prospect_country="garbage!!")++def test_from_config_reads_prospect_country():config = SimpleNamespace(compliance=SimpleNamespace(precleared=PreclearedConfig(