Spaces:
Sleeping
Sleeping
docs: rule on the Task 11 validator findings
Browse filesTwo Critical, both reproduced live. _normalise stripped trailing zeros from
integers, so "100" became "1" and a draft claiming a 5.4% position was 100% of
the portfolio passed with zero violations; and the offer's price string was
tokenised into the allowed set, licensing any single-digit figure. The offer
text is now removed from the body before the scan rather than added to the set,
and magnitude survives normalisation. Separately, anything the model wrote after
the RGPD placeholder escaped the number check entirely.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016XzekHxqiXutBW4gw3Arsx
docs/superpowers/plans/2026-08-29-prospection-buyside.md
CHANGED
|
@@ -3430,6 +3430,45 @@ def test_draft_with_an_unsupported_number_is_rejected():
|
|
| 3430 |
assert "chiffre_non_source" in compose.validate_draft(draft, _bundle())
|
| 3431 |
|
| 3432 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3433 |
def test_draft_with_a_superlative_is_rejected():
|
| 3434 |
draft = _valid_draft().replace("Ci-joint le brief", "Ci-joint le meilleur brief")
|
| 3435 |
assert "superlatif" in compose.validate_draft(draft, _bundle())
|
|
@@ -3480,6 +3519,26 @@ def test_no_evidence_bundle_is_refused_before_reaching_the_model():
|
|
| 3480 |
with pytest.raises(compose.ComposeRejected):
|
| 3481 |
compose.compose(_bundle(evidence="no_evidence", holding=None, demo=None),
|
| 3482 |
llm=lambda prompt: _valid_draft())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3483 |
```
|
| 3484 |
|
| 3485 |
- [ ] **Step 2: Lancer le test pour vérifier qu'il échoue**
|
|
@@ -3608,8 +3667,14 @@ RGPD_PLACEHOLDER = "{{RGPD}}"
|
|
| 3608 |
|
| 3609 |
_SUPERLATIVES = ("meilleur", "meilleure", "leader", "unique en son genre", "révolutionnaire",
|
| 3610 |
"incontournable", "exceptionnel", "inégalé", "le plus performant")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3611 |
_INVESTMENT_ADVICE = ("recommande d'acheter", "recommande de vendre", "objectif de cours",
|
| 3612 |
-
"
|
|
|
|
|
|
|
| 3613 |
"achetez", "vendez")
|
| 3614 |
_NUMBER_RE = re.compile(r"\d+(?:[.,]\d+)?")
|
| 3615 |
|
|
@@ -3629,21 +3694,45 @@ class EvidenceBundle:
|
|
| 3629 |
|
| 3630 |
|
| 3631 |
def _normalise(number: str) -> str:
|
| 3632 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3633 |
|
| 3634 |
|
| 3635 |
def allowed_numbers(bundle: EvidenceBundle) -> set[str]:
|
| 3636 |
-
"""
|
| 3637 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3638 |
holding = bundle.holding or {}
|
| 3639 |
-
|
| 3640 |
-
|
| 3641 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3642 |
chosen = offer_module.offer_for(bundle.evidence)
|
| 3643 |
-
|
| 3644 |
-
|
| 3645 |
-
|
| 3646 |
-
return {_normalise(n) for text in pool for n in _NUMBER_RE.findall(str(text))}
|
| 3647 |
|
| 3648 |
|
| 3649 |
def validate_draft(draft: str, bundle: EvidenceBundle) -> list[str]:
|
|
@@ -3652,6 +3741,11 @@ def validate_draft(draft: str, bundle: EvidenceBundle) -> list[str]:
|
|
| 3652 |
|
| 3653 |
if RGPD_PLACEHOLDER not in draft and "registre amf des sgp" not in lowered:
|
| 3654 |
violations.append("bloc_rgpd_absent")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3655 |
if len(draft.split()) > config.MAX_EMAIL_WORDS:
|
| 3656 |
violations.append("trop_long")
|
| 3657 |
if any(word in lowered for word in _SUPERLATIVES):
|
|
@@ -3659,16 +3753,18 @@ def validate_draft(draft: str, bundle: EvidenceBundle) -> list[str]:
|
|
| 3659 |
if any(phrase in lowered for phrase in _INVESTMENT_ADVICE):
|
| 3660 |
violations.append("recommandation_investissement")
|
| 3661 |
|
| 3662 |
-
body = draft.split(RGPD_PLACEHOLDER)[0]
|
| 3663 |
permitted = allowed_numbers(bundle)
|
|
|
|
| 3664 |
if any(_normalise(n) not in permitted for n in _NUMBER_RE.findall(body)):
|
| 3665 |
violations.append("chiffre_non_source")
|
| 3666 |
return violations
|
| 3667 |
|
| 3668 |
|
| 3669 |
-
def build_prompt(bundle: EvidenceBundle) -> str:
|
| 3670 |
holding = bundle.holding or {}
|
| 3671 |
chosen = offer_module.offer_for(bundle.evidence)
|
|
|
|
|
|
|
| 3672 |
template = email_fr.TEMPLATES[bundle.evidence].format(
|
| 3673 |
prenom=bundle.contact.get("prenom") or "",
|
| 3674 |
nom=bundle.contact.get("nom") or "",
|
|
@@ -3694,6 +3790,12 @@ def build_prompt(bundle: EvidenceBundle) -> str:
|
|
| 3694 |
f"- Arrêté au : {holding.get('as_of')}\n"
|
| 3695 |
f"- Source : {holding.get('source_url')}\n\n"
|
| 3696 |
f"CONSIGNE\n{template}\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3697 |
)
|
| 3698 |
|
| 3699 |
|
|
@@ -3710,10 +3812,12 @@ def compose(bundle: EvidenceBundle, llm=None, max_attempts: int = 3) -> str:
|
|
| 3710 |
raise ComposeRejected("aucune preuve : ce compte ne reçoit pas de message personnalisé")
|
| 3711 |
|
| 3712 |
generate = llm or _default_llm
|
| 3713 |
-
prompt = build_prompt(bundle)
|
| 3714 |
last: list[str] = []
|
| 3715 |
for _ in range(max_attempts):
|
| 3716 |
-
|
|
|
|
|
|
|
|
|
|
| 3717 |
last = validate_draft(draft, bundle)
|
| 3718 |
if not last:
|
| 3719 |
return draft.replace(RGPD_PLACEHOLDER, render_rgpd_block())
|
|
|
|
| 3430 |
assert "chiffre_non_source" in compose.validate_draft(draft, _bundle())
|
| 3431 |
|
| 3432 |
|
| 3433 |
+
def test_a_fabricated_round_number_is_rejected():
|
| 3434 |
+
"""Le piège : « 100 » dont on retire les zéros de fin devient « 1 », et passait
|
| 3435 |
+
donc au motif qu'un « 1 » figurait quelque part. Une position à 5,4 % annoncée
|
| 3436 |
+
à 100 % du portefeuille est la fabrication la plus grossière possible."""
|
| 3437 |
+
draft = _valid_draft().replace("5.4 %", "100 %")
|
| 3438 |
+
assert "chiffre_non_source" in compose.validate_draft(draft, _bundle())
|
| 3439 |
+
|
| 3440 |
+
|
| 3441 |
+
def test_a_fabricated_upside_figure_is_rejected():
|
| 3442 |
+
draft = _valid_draft().replace(
|
| 3443 |
+
"Ci-joint le brief", "Le titre offre 20 % de potentiel. Ci-joint le brief")
|
| 3444 |
+
assert "chiffre_non_source" in compose.validate_draft(draft, _bundle())
|
| 3445 |
+
|
| 3446 |
+
|
| 3447 |
+
def test_the_offer_wording_does_not_trip_the_number_check():
|
| 3448 |
+
"""Le libellé de l'offre est du texte que nous fournissons : il est retiré du
|
| 3449 |
+
corps avant l'analyse, pas ajouté à l'ensemble autorisé."""
|
| 3450 |
+
chosen = offer.offer_for("holdings_verified")
|
| 3451 |
+
draft = _valid_draft().replace(
|
| 3452 |
+
"Un pilote de cadrage de trois semaines couvre vos dix principales lignes.",
|
| 3453 |
+
f"Un pilote de cadrage ({chosen.duree}, {chosen.prix}).")
|
| 3454 |
+
assert compose.validate_draft(draft, _bundle()) == []
|
| 3455 |
+
|
| 3456 |
+
|
| 3457 |
+
def test_text_after_the_rgpd_block_cannot_escape_the_number_check():
|
| 3458 |
+
"""Tout ce qui suit le placeholder échappait au contrôle : un post-scriptum
|
| 3459 |
+
inventant « 47 % de hausse » passait sans une seule violation."""
|
| 3460 |
+
draft = _valid_draft() + "\n\nP.S. Ce titre offre un potentiel de 47 % de hausse."
|
| 3461 |
+
assert "bloc_rgpd_mal_place" in compose.validate_draft(draft, _bundle())
|
| 3462 |
+
|
| 3463 |
+
|
| 3464 |
+
def test_a_price_target_in_ordinary_french_is_rejected():
|
| 3465 |
+
"""« cours cible » est la formulation courante d'un objectif de cours, que la
|
| 3466 |
+
contrainte produit interdit sans exception."""
|
| 3467 |
+
draft = _valid_draft().replace(
|
| 3468 |
+
"Ci-joint le brief", "Notre cours cible reste au-dessus. Ci-joint le brief")
|
| 3469 |
+
assert "recommandation_investissement" in compose.validate_draft(draft, _bundle())
|
| 3470 |
+
|
| 3471 |
+
|
| 3472 |
def test_draft_with_a_superlative_is_rejected():
|
| 3473 |
draft = _valid_draft().replace("Ci-joint le brief", "Ci-joint le meilleur brief")
|
| 3474 |
assert "superlatif" in compose.validate_draft(draft, _bundle())
|
|
|
|
| 3519 |
with pytest.raises(compose.ComposeRejected):
|
| 3520 |
compose.compose(_bundle(evidence="no_evidence", holding=None, demo=None),
|
| 3521 |
llm=lambda prompt: _valid_draft())
|
| 3522 |
+
|
| 3523 |
+
|
| 3524 |
+
def test_an_unknown_evidence_level_fails_closed():
|
| 3525 |
+
"""Un module fail-closed doit échouer fermé, pas par KeyError."""
|
| 3526 |
+
with pytest.raises(compose.ComposeRejected):
|
| 3527 |
+
compose.build_prompt(_bundle(evidence="something_else"))
|
| 3528 |
+
|
| 3529 |
+
|
| 3530 |
+
def test_a_retry_tells_the_model_what_was_wrong():
|
| 3531 |
+
"""Le modèle tourne à température 0 : relancer la même consigne reproduirait
|
| 3532 |
+
le même brouillon, et les tentatives suivantes ne serviraient à rien."""
|
| 3533 |
+
seen: list[str] = []
|
| 3534 |
+
|
| 3535 |
+
def _llm(prompt: str) -> str:
|
| 3536 |
+
seen.append(prompt)
|
| 3537 |
+
return _valid_draft() if len(seen) > 1 else _valid_draft().replace("5.4 %", "9.7 %")
|
| 3538 |
+
|
| 3539 |
+
compose.compose(_bundle(), llm=_llm)
|
| 3540 |
+
assert "chiffre_non_source" in seen[1]
|
| 3541 |
+
assert "chiffre_non_source" not in seen[0]
|
| 3542 |
```
|
| 3543 |
|
| 3544 |
- [ ] **Step 2: Lancer le test pour vérifier qu'il échoue**
|
|
|
|
| 3667 |
|
| 3668 |
_SUPERLATIVES = ("meilleur", "meilleure", "leader", "unique en son genre", "révolutionnaire",
|
| 3669 |
"incontournable", "exceptionnel", "inégalé", "le plus performant")
|
| 3670 |
+
# La contrainte produit est « aucune recommandation d'achat ou de vente, aucun
|
| 3671 |
+
# objectif de cours, jamais ». « cours cible » est la formulation française
|
| 3672 |
+
# ordinaire d'un objectif de cours : l'omettre laissait passer précisément ce que
|
| 3673 |
+
# la contrainte interdit.
|
| 3674 |
_INVESTMENT_ADVICE = ("recommande d'acheter", "recommande de vendre", "objectif de cours",
|
| 3675 |
+
"cours cible", "objectif de prix", "acheter cette valeur",
|
| 3676 |
+
"vendre cette valeur", "price target", "conseil d'achat",
|
| 3677 |
+
"signal d'achat", "à l'achat", "surpondérer", "sous-pondérer",
|
| 3678 |
"achetez", "vendez")
|
| 3679 |
_NUMBER_RE = re.compile(r"\d+(?:[.,]\d+)?")
|
| 3680 |
|
|
|
|
| 3694 |
|
| 3695 |
|
| 3696 |
def _normalise(number: str) -> str:
|
| 3697 |
+
"""Les zéros de fin ne tombent qu'après une virgule décimale.
|
| 3698 |
+
|
| 3699 |
+
Les supprimer d'un entier détruisait l'ordre de grandeur : « 100 » devenait
|
| 3700 |
+
« 1 », si bien qu'un brouillon affirmant qu'une position pèse 100 % du
|
| 3701 |
+
portefeuille passait au motif qu'un « 1 » figurait quelque part dans les
|
| 3702 |
+
faits. C'est exactement la fabrication que ce module existe pour arrêter.
|
| 3703 |
+
"""
|
| 3704 |
+
value = number.replace(",", ".")
|
| 3705 |
+
if "." in value:
|
| 3706 |
+
value = value.rstrip("0").rstrip(".")
|
| 3707 |
+
return value or "0"
|
| 3708 |
|
| 3709 |
|
| 3710 |
def allowed_numbers(bundle: EvidenceBundle) -> set[str]:
|
| 3711 |
+
"""Les seuls nombres qu'un brouillon peut porter : ceux du fait stocké.
|
| 3712 |
+
|
| 3713 |
+
L'offre n'y figure pas. Passer « 6 000 à 9 000 € » dans le même extracteur de
|
| 3714 |
+
chiffres y injectait 6, 000 et 9, ce qui autorisait ensuite n'importe quel
|
| 3715 |
+
montant à un chiffre inventé. Le texte de l'offre est du contenu que nous
|
| 3716 |
+
fournissons : il est RETIRÉ du corps avant l'analyse (`_body_for_numbers`)
|
| 3717 |
+
plutôt qu'ajouté à l'ensemble autorisé.
|
| 3718 |
+
"""
|
| 3719 |
holding = bundle.holding or {}
|
| 3720 |
+
return {
|
| 3721 |
+
_normalise(n)
|
| 3722 |
+
for value in (holding.get("weight_pct"), holding.get("as_of"))
|
| 3723 |
+
if value is not None
|
| 3724 |
+
for n in _NUMBER_RE.findall(str(value))
|
| 3725 |
+
}
|
| 3726 |
+
|
| 3727 |
+
|
| 3728 |
+
def _body_for_numbers(draft: str, bundle: EvidenceBundle) -> str:
|
| 3729 |
+
"""Corps soumis au contrôle des chiffres : sans le bloc RGPD ni le libellé de
|
| 3730 |
+
l'offre, qui sont l'un et l'autre du texte que nous avons écrit."""
|
| 3731 |
+
body = draft.split(RGPD_PLACEHOLDER)[0]
|
| 3732 |
chosen = offer_module.offer_for(bundle.evidence)
|
| 3733 |
+
for supplied in (chosen.duree, chosen.prix):
|
| 3734 |
+
body = body.replace(supplied, " ")
|
| 3735 |
+
return body
|
|
|
|
| 3736 |
|
| 3737 |
|
| 3738 |
def validate_draft(draft: str, bundle: EvidenceBundle) -> list[str]:
|
|
|
|
| 3741 |
|
| 3742 |
if RGPD_PLACEHOLDER not in draft and "registre amf des sgp" not in lowered:
|
| 3743 |
violations.append("bloc_rgpd_absent")
|
| 3744 |
+
elif RGPD_PLACEHOLDER in draft and not draft.rstrip().endswith(RGPD_PLACEHOLDER):
|
| 3745 |
+
# Le placeholder doit terminer le brouillon. Sinon tout ce que le modèle
|
| 3746 |
+
# écrit après lui — un post-scriptum, une signature — échappe au contrôle
|
| 3747 |
+
# des chiffres, qui ne lit que ce qui précède.
|
| 3748 |
+
violations.append("bloc_rgpd_mal_place")
|
| 3749 |
if len(draft.split()) > config.MAX_EMAIL_WORDS:
|
| 3750 |
violations.append("trop_long")
|
| 3751 |
if any(word in lowered for word in _SUPERLATIVES):
|
|
|
|
| 3753 |
if any(phrase in lowered for phrase in _INVESTMENT_ADVICE):
|
| 3754 |
violations.append("recommandation_investissement")
|
| 3755 |
|
|
|
|
| 3756 |
permitted = allowed_numbers(bundle)
|
| 3757 |
+
body = _body_for_numbers(draft, bundle)
|
| 3758 |
if any(_normalise(n) not in permitted for n in _NUMBER_RE.findall(body)):
|
| 3759 |
violations.append("chiffre_non_source")
|
| 3760 |
return violations
|
| 3761 |
|
| 3762 |
|
| 3763 |
+
def build_prompt(bundle: EvidenceBundle, violations: list[str] | None = None) -> str:
|
| 3764 |
holding = bundle.holding or {}
|
| 3765 |
chosen = offer_module.offer_for(bundle.evidence)
|
| 3766 |
+
if bundle.evidence not in email_fr.TEMPLATES:
|
| 3767 |
+
raise ComposeRejected(f"niveau de preuve inconnu : {bundle.evidence!r}")
|
| 3768 |
template = email_fr.TEMPLATES[bundle.evidence].format(
|
| 3769 |
prenom=bundle.contact.get("prenom") or "",
|
| 3770 |
nom=bundle.contact.get("nom") or "",
|
|
|
|
| 3790 |
f"- Arrêté au : {holding.get('as_of')}\n"
|
| 3791 |
f"- Source : {holding.get('source_url')}\n\n"
|
| 3792 |
f"CONSIGNE\n{template}\n"
|
| 3793 |
+
+ (
|
| 3794 |
+
"\nLA TENTATIVE PRÉCÉDENTE A ÉTÉ REJETÉE POUR : "
|
| 3795 |
+
+ ", ".join(violations)
|
| 3796 |
+
+ ".\nCorrige exactement ces points."
|
| 3797 |
+
if violations else ""
|
| 3798 |
+
)
|
| 3799 |
)
|
| 3800 |
|
| 3801 |
|
|
|
|
| 3812 |
raise ComposeRejected("aucune preuve : ce compte ne reçoit pas de message personnalisé")
|
| 3813 |
|
| 3814 |
generate = llm or _default_llm
|
|
|
|
| 3815 |
last: list[str] = []
|
| 3816 |
for _ in range(max_attempts):
|
| 3817 |
+
# Les motifs de rejet précédents repartent dans la consigne : le modèle
|
| 3818 |
+
# tourne à température 0, donc une relance identique reproduirait le même
|
| 3819 |
+
# brouillon et les tentatives suivantes ne serviraient à rien.
|
| 3820 |
+
draft = generate(build_prompt(bundle, last))
|
| 3821 |
last = validate_draft(draft, bundle)
|
| 3822 |
if not last:
|
| 3823 |
return draft.replace(RGPD_PLACEHOLDER, render_rgpd_block())
|