Skip to content

fix(email): the word confidential is not a disclaimer - #227

Merged
NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
PerryLink:fix/confidential-is-not-a-disclaimer
Sep 23, 2026
Merged

NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
PerryLink:fix/confidential-is-not-a-disclaimer

Conversation

@PerryLink

Copy link
Copy Markdown
Contributor

fix(email): the word "confidential" is not a disclaimer

_DISCLAIMER matched the bare word confidential, and _strip_disclaimer drops any
sentence that matches. A body whose only sentence mentions the word was therefore
deleted whole and returned as "", with no error and no warning, so email_state
built a state with an empty body and the model was scored on nothing:

>>> from laya.email import clean_email_body, email_state
>>> clean_email_body("Is this confidential?")
''                                     # before: the request, deleted
>>> email_state("Question", "Is this confidential?")["body"]
''

The Portuguese and Spanish branches directly below the English one are already tied to
disclaimer phrasing rather than a bare word, and the comment above them gives this
exact reason: a sender's own request ("preciso do contrato confidencial") uses the
word just as often as a footer does. English never got the same treatment, so
confidential cut anything that merely mentioned it:

body before
Is this confidential? ''
What is your confidentiality policy? ''
Please treat this as confidential. ''
Confidential: I need a refund. ''
Please keep this confidential but process my refund. ''
Is the attached document confidential? ''

Real footers are unaffected, because a footer names what is confidential and who it is
for, and that is what the new English branch keys on:

body after
This email is confidential and intended solely for the named addressee. dropped
This message is confidential and intended solely for the use of the individual to whom it is addressed. dropped
The information in this email is confidential and may be privileged. dropped
This email and any files transmitted with it are
confidential and intended solely for the named addressee.
dropped
My account is locked.\nThis email is confidential and intended solely for the named addressee.\nPlease unlock it. My account is locked. Please unlock it.

Deliberate choices tested:

  • Tied to a disclaimer noun, not to position or length. \b(e-?mail|message|information|communication|transmission|contents?)\b[^.]{0,60}\bconfidential\b[^.]{0,60}\b(intended|solely|addressee|recipient|privileged|disclos|unauthori[sz]ed) keeps What is the information policy for contractors? and Please confirm the recipient address for invoice 4411. while still cutting the footers above. Requiring only the tail word (intended/solely) instead of a disclaimer noun let Please treat this as confidential. through as well as the footer, which is no separation at all.
  • [^.] rather than [^.\n] inside the gap. A footer wraps, so are\nconfidential has to match; a fixture for exactly that is in the suite. The gap is still capped at 60 characters.
  • and (may|is) (also )?privileged is its own branch, because that footer usually has no disclaimer noun in front of it.
  • if you (have )?received this ... in error is unchanged. It was never a bare word and its behaviour is pinned by an existing test.
  • No fallback guard added. "Never return empty for non-empty input" also stops the loss, but it would keep a standalone footer that is the entire body, which the existing suite asserts must be dropped. Narrowing the marker fixes the cause; the guard would have hidden it.

The intended (solely )?for the (use of the )?(named )?(addressee|recipient) form moved
inside the noun-anchored branch rather than being deleted, so intended solely for the named addressee is still matched.

Verified with the real package:

$ python tests/test_email.py        62 passed, 0 failed      (46 before this PR's cases)
$ python tests/test_criteria.py     72 passed, 0 failed
$ python tests/test_router.py       all routing tests passed
$ python research/eval/test_laya_eval.py   62 passed, 0 failed
$ python -m ruff check laya/ --select=E9,F63,F7,F82,F401,F811 --line-length=120
All checks passed!

Nine of the new cases fail against the unfixed module and pass after, so the suite
catches this specific defect rather than describing it:

# with `confidential` restored as a bare word
53 passed, 9 failed
  FAIL word only/kept: a question about the word
  FAIL word only/kept: a policy question
  FAIL word only/kept: a request containing the word
  FAIL word only/kept: a request about handling
  FAIL word only/kept: a question with a dash
  FAIL word only/kept: a question about an attachment
  FAIL word only/kept: a label prefix
  FAIL word only/body is never emptied
  FAIL word only/email_state keeps the request

Known limitation: this narrows the English confidential branch, so a genuine footer
that says only This is confidential. with no noun and no addressee tail is now kept
rather than dropped. That is the same keep-ward trade-off the module already documents
for the capitalised continuation in tests/test_email.py:61-69: leaving one boilerplate
line behind is harmless, deleting the sender's request is not.

`_DISCLAIMER` matched the bare word `confidential`, and `_strip_disclaimer` drops any
sentence that matches. A body whose only sentence mentions the word was therefore
deleted whole and returned as `""`, with no error and no warning, so `email_state`
built a state with an empty body and the model was scored on nothing:

    >>> from laya.email import clean_email_body, email_state
    >>> clean_email_body("Is this confidential?")
    ''                                     # before: the request, deleted
    >>> email_state("Question", "Is this confidential?")["body"]
    ''

The Portuguese and Spanish branches directly below the English one are already tied to
disclaimer phrasing rather than a bare word, and the comment above them gives this
exact reason: a sender's own request (`"preciso do contrato confidencial"`) uses the
word just as often as a footer does. English never got the same treatment, so
`confidential` cut anything that merely mentioned it:

| body | before |
|---|---|
| `Is this confidential?` | `''` |
| `What is your confidentiality policy?` | `''` |
| `Please treat this as confidential.` | `''` |
| `Confidential: I need a refund.` | `''` |
| `Please keep this confidential but process my refund.` | `''` |
| `Is the attached document confidential?` | `''` |

Real footers are unaffected, because a footer names what is confidential and who it is
for, and that is what the new English branch keys on:

| body | after |
|---|---|
| `This email is confidential and intended solely for the named addressee.` | dropped |
| `This message is confidential and intended solely for the use of the individual to whom it is addressed.` | dropped |
| `The information in this email is confidential and may be privileged.` | dropped |
| `This email and any files transmitted with it are`<br>`confidential and intended solely for the named addressee.` | dropped |
| `My account is locked.\nThis email is confidential and intended solely for the named addressee.\nPlease unlock it.` | `My account is locked. Please unlock it.` |

Deliberate choices tested:

- **Tied to a disclaimer noun, not to position or length.** `\b(e-?mail|message|information|communication|transmission|contents?)\b[^.]{0,60}\bconfidential\b[^.]{0,60}\b(intended|solely|addressee|recipient|privileged|disclos|unauthori[sz]ed)` keeps `What is the information policy for contractors?` and `Please confirm the recipient address for invoice 4411.` while still cutting the footers above. Requiring only the tail word (`intended`/`solely`) instead of a disclaimer noun let `Please treat this as confidential.` through as well as the footer, which is no separation at all.
- **`[^.]` rather than `[^.\n]` inside the gap.** A footer wraps, so `are\nconfidential` has to match; a fixture for exactly that is in the suite. The gap is still capped at 60 characters.
- **`and (may|is) (also )?privileged` is its own branch**, because that footer usually has no disclaimer noun in front of it.
- **`if you (have )?received this ... in error` is unchanged.** It was never a bare word and its behaviour is pinned by an existing test.
- **No fallback guard added.** "Never return empty for non-empty input" also stops the loss, but it would keep a standalone footer that is the entire body, which the existing suite asserts must be dropped. Narrowing the marker fixes the cause; the guard would have hidden it.

The `intended (solely )?for the (use of the )?(named )?(addressee|recipient)` form moved
inside the noun-anchored branch rather than being deleted, so `intended solely for the
named addressee` is still matched.

Verified with the real package:

```
$ python tests/test_email.py        62 passed, 0 failed      (46 before this PR's cases)
$ python tests/test_criteria.py     72 passed, 0 failed
$ python tests/test_router.py       all routing tests passed
$ python research/eval/test_laya_eval.py   62 passed, 0 failed
$ python -m ruff check laya/ --select=E9,F63,F7,F82,F401,F811 --line-length=120
All checks passed!
```

Nine of the new cases fail against the unfixed module and pass after, so the suite
catches this specific defect rather than describing it:

```
# with `confidential` restored as a bare word
53 passed, 9 failed
  FAIL word only/kept: a question about the word
  FAIL word only/kept: a policy question
  FAIL word only/kept: a request containing the word
  FAIL word only/kept: a request about handling
  FAIL word only/kept: a question with a dash
  FAIL word only/kept: a question about an attachment
  FAIL word only/kept: a label prefix
  FAIL word only/body is never emptied
  FAIL word only/email_state keeps the request
```

Known limitation: this narrows the English `confidential` branch, so a genuine footer
that says only `This is confidential.` with no noun and no addressee tail is now kept
rather than dropped. That is the same keep-ward trade-off the module already documents
for the capitalised continuation in `tests/test_email.py:61-69`: leaving one boilerplate
line behind is harmless, deleting the sender's request is not.
@NandhaKishorM

Copy link
Copy Markdown
Owner

Thank you. Deleting "Is this confidential?" whole and scoring an empty body is a silent failure, the worst kind for email triage. Tying the English rule to a disclaimer noun and tail, the way the Portuguese rule already works, is the right shape. Merging.

@NandhaKishorM
NandhaKishorM merged commit 7599902 into NandhaKishorM:main Sep 23, 2026
13 checks passed
baninaveen pushed a commit to baninaveen/laya that referenced this pull request Sep 24, 2026
…M#227)

`_DISCLAIMER` matched the bare word `confidential`, and `_strip_disclaimer` drops any
sentence that matches. A body whose only sentence mentions the word was therefore
deleted whole and returned as `""`, with no error and no warning, so `email_state`
built a state with an empty body and the model was scored on nothing:

    >>> from laya.email import clean_email_body, email_state
    >>> clean_email_body("Is this confidential?")
    ''                                     # before: the request, deleted
    >>> email_state("Question", "Is this confidential?")["body"]
    ''

The Portuguese and Spanish branches directly below the English one are already tied to
disclaimer phrasing rather than a bare word, and the comment above them gives this
exact reason: a sender's own request (`"preciso do contrato confidencial"`) uses the
word just as often as a footer does. English never got the same treatment, so
`confidential` cut anything that merely mentioned it:

| body | before |
|---|---|
| `Is this confidential?` | `''` |
| `What is your confidentiality policy?` | `''` |
| `Please treat this as confidential.` | `''` |
| `Confidential: I need a refund.` | `''` |
| `Please keep this confidential but process my refund.` | `''` |
| `Is the attached document confidential?` | `''` |

Real footers are unaffected, because a footer names what is confidential and who it is
for, and that is what the new English branch keys on:

| body | after |
|---|---|
| `This email is confidential and intended solely for the named addressee.` | dropped |
| `This message is confidential and intended solely for the use of the individual to whom it is addressed.` | dropped |
| `The information in this email is confidential and may be privileged.` | dropped |
| `This email and any files transmitted with it are`<br>`confidential and intended solely for the named addressee.` | dropped |
| `My account is locked.\nThis email is confidential and intended solely for the named addressee.\nPlease unlock it.` | `My account is locked. Please unlock it.` |

Deliberate choices tested:

- **Tied to a disclaimer noun, not to position or length.** `\b(e-?mail|message|information|communication|transmission|contents?)\b[^.]{0,60}\bconfidential\b[^.]{0,60}\b(intended|solely|addressee|recipient|privileged|disclos|unauthori[sz]ed)` keeps `What is the information policy for contractors?` and `Please confirm the recipient address for invoice 4411.` while still cutting the footers above. Requiring only the tail word (`intended`/`solely`) instead of a disclaimer noun let `Please treat this as confidential.` through as well as the footer, which is no separation at all.
- **`[^.]` rather than `[^.\n]` inside the gap.** A footer wraps, so `are\nconfidential` has to match; a fixture for exactly that is in the suite. The gap is still capped at 60 characters.
- **`and (may|is) (also )?privileged` is its own branch**, because that footer usually has no disclaimer noun in front of it.
- **`if you (have )?received this ... in error` is unchanged.** It was never a bare word and its behaviour is pinned by an existing test.
- **No fallback guard added.** "Never return empty for non-empty input" also stops the loss, but it would keep a standalone footer that is the entire body, which the existing suite asserts must be dropped. Narrowing the marker fixes the cause; the guard would have hidden it.

The `intended (solely )?for the (use of the )?(named )?(addressee|recipient)` form moved
inside the noun-anchored branch rather than being deleted, so `intended solely for the
named addressee` is still matched.

Verified with the real package:

```
$ python tests/test_email.py        62 passed, 0 failed      (46 before this PR's cases)
$ python tests/test_criteria.py     72 passed, 0 failed
$ python tests/test_router.py       all routing tests passed
$ python research/eval/test_laya_eval.py   62 passed, 0 failed
$ python -m ruff check laya/ --select=E9,F63,F7,F82,F401,F811 --line-length=120
All checks passed!
```

Nine of the new cases fail against the unfixed module and pass after, so the suite
catches this specific defect rather than describing it:

```
# with `confidential` restored as a bare word
53 passed, 9 failed
  FAIL word only/kept: a question about the word
  FAIL word only/kept: a policy question
  FAIL word only/kept: a request containing the word
  FAIL word only/kept: a request about handling
  FAIL word only/kept: a question with a dash
  FAIL word only/kept: a question about an attachment
  FAIL word only/kept: a label prefix
  FAIL word only/body is never emptied
  FAIL word only/email_state keeps the request
```

Known limitation: this narrows the English `confidential` branch, so a genuine footer
that says only `This is confidential.` with no noun and no addressee tail is now kept
rather than dropped. That is the same keep-ward trade-off the module already documents
for the capitalised continuation in `tests/test_email.py:61-69`: leaving one boilerplate
line behind is harmless, deleting the sender's request is not.

Co-authored-by: PerryLink <255665900+PerryLink@users.noreply.github.com>
PerryLink added a commit to PerryLink/laya that referenced this pull request Sep 24, 2026
The English quote-header marker was `^\s*From:\s.+$`, which matches any line that starts
`From: `. Ordinary prose opens that way, so the request was deleted and the model answered an
empty body — the same silent failure this module has been fixed for twice already (NandhaKishorM#94, NandhaKishorM#227):

```python
from laya import email

body = ("Hi team,\n"
        "From: my side the integration works, but please refund the duplicate charge today.\n"
        "Thanks")
print(email.clean_email_body(body))

# before
# 'Hi team,'
#   -> "refund" in cleaned is False; the model never sees the request

# after
# 'Hi team,\nFrom: my side the integration works, but please refund the duplicate charge today.\nThanks'
```

The `De:` marker two lines below already had this exact fix, for the same reason and with a
comment saying so — `De:` also opens ordinary Portuguese/Spanish lines. `From:` opens ordinary
English lines, and a reply header always carries the sender, so it is now gated on an address
the same way:

```python
re.compile(r"^\s*From:\s.*[@<]", re.I),   # was r"^\s*From:\s.+$"
```

Deliberate choices tested:

- **Gate on an address rather than on the shape of the text.** A word-count or capitalisation rule would be guessing at what a sentence looks like; "a reply header names its sender" is a property of the header, and it is the rule `De:` already uses, so the two now read the same way instead of one being stricter for no stated reason.
- **A bare `From: Name` header is still cut, by its neighbours.** This is the part I got wrong first: I assumed `_SIGNATURE_MARKERS` covered `Sent:`, but `_HEADER_NEXT` only listed the Portuguese/Spanish `Enviado:`/`Data:`/`Fecha:` forms, so dropping the address from the marker leaked every English quote header written without one. `_HEADER_FROM_NAME`/`_HEADER_NEXT` now accept the English pair too — `From: <name>` followed by `Sent:` or a dated `Date:` — which is the translation of the rule that was already there for `De:`.
- **`To:` alone is still not enough**, matching the existing note that "`De: 10/09 / Para: 15/09` is how a leave request reads". `From: Alice Smith` followed by `To: Bob` and a request is kept, because a `To:` line is not evidence of a quote block.
- **When it cannot be told apart, the request wins.** A bare `From: Name` with no header neighbour is kept. A leaked quote is noise the model can read past; a deleted request is a wrong answer, which is the asymmetry NandhaKishorM#94 and NandhaKishorM#227 were both about.

The suite had **no `From:` case at all** before this, which is why it stayed green on the bug —
`python tests/test_email.py` reported `90 passed, 0 failed` on `main` with the bug present. The
new block covers five prose forms, the four quoted-header forms that must still cut, and the two
ambiguous forms that must be kept:

```
# with the marker reverted to r"^\s*From:\s.+$"
98 passed, 7 failed
  FAIL en/`From:` prose keeps the request: the reported case Hi team,
  FAIL en/`From:` prose keeps the request: lowercase Hi,
  FAIL en/`From:` prose keeps the request: uppercase Hi,
  FAIL en/`From:` prose keeps the request: extra spacing Hi,
  FAIL en/`From:` prose keeps the request: mid-body Hello,
  FAIL en/bare `From:` with no header neighbour is kept: From: Name then To: Hi,
  FAIL en/bare `From:` with no header neighbour is kept: From: Name alone Hi,

# restored
105 passed, 0 failed
```

The four quoted-header positive controls stay green in both states, so the fix is not simply
"stop cutting on `From:`".

```
$ python tests/test_email.py                  105 passed, 0 failed   (90 before)
$ python tests/test_lang_guess.py             52 passed, 0 failed
$ python tests/test_router.py                 all routing tests passed
$ python tests/test_criteria.py               128 passed, 0 failed
$ python tests/test_packaging.py              all packaging tests passed
$ python -m ruff check laya/ --select=E9,F63,F7,F82,F401,F811 --line-length=120
All checks passed!
$ python -m compileall -q laya/ tests/
```

Known limitation: `From:` followed by an address but no other header line is treated as a quote
header and cut, because that is what an address on a `From:` line overwhelmingly is in an email
body. A caller who writes prose that literally begins `From: <someone@example.com>` loses that
line; I could not construct a realistic case where that is a request, and the quoted-header case
is the common one.
@PerryLink PerryLink mentioned this pull request Sep 24, 2026
2 of 4 tasks
baninaveen pushed a commit to baninaveen/laya that referenced this pull request Sep 25, 2026
The English quote-header marker was `^\s*From:\s.+$`, which matches any line that starts
`From: `. Ordinary prose opens that way, so the request was deleted and the model answered an
empty body — the same silent failure this module has been fixed for twice already (NandhaKishorM#94, NandhaKishorM#227):

```python
from laya import email

body = ("Hi team,\n"
        "From: my side the integration works, but please refund the duplicate charge today.\n"
        "Thanks")
print(email.clean_email_body(body))

# before
# 'Hi team,'
#   -> "refund" in cleaned is False; the model never sees the request

# after
# 'Hi team,\nFrom: my side the integration works, but please refund the duplicate charge today.\nThanks'
```

The `De:` marker two lines below already had this exact fix, for the same reason and with a
comment saying so — `De:` also opens ordinary Portuguese/Spanish lines. `From:` opens ordinary
English lines, and a reply header always carries the sender, so it is now gated on an address
the same way:

```python
re.compile(r"^\s*From:\s.*[@<]", re.I),   # was r"^\s*From:\s.+$"
```

Deliberate choices tested:

- **Gate on an address rather than on the shape of the text.** A word-count or capitalisation rule would be guessing at what a sentence looks like; "a reply header names its sender" is a property of the header, and it is the rule `De:` already uses, so the two now read the same way instead of one being stricter for no stated reason.
- **A bare `From: Name` header is still cut, by its neighbours.** This is the part I got wrong first: I assumed `_SIGNATURE_MARKERS` covered `Sent:`, but `_HEADER_NEXT` only listed the Portuguese/Spanish `Enviado:`/`Data:`/`Fecha:` forms, so dropping the address from the marker leaked every English quote header written without one. `_HEADER_FROM_NAME`/`_HEADER_NEXT` now accept the English pair too — `From: <name>` followed by `Sent:` or a dated `Date:` — which is the translation of the rule that was already there for `De:`.
- **`To:` alone is still not enough**, matching the existing note that "`De: 10/09 / Para: 15/09` is how a leave request reads". `From: Alice Smith` followed by `To: Bob` and a request is kept, because a `To:` line is not evidence of a quote block.
- **When it cannot be told apart, the request wins.** A bare `From: Name` with no header neighbour is kept. A leaked quote is noise the model can read past; a deleted request is a wrong answer, which is the asymmetry NandhaKishorM#94 and NandhaKishorM#227 were both about.

The suite had **no `From:` case at all** before this, which is why it stayed green on the bug —
`python tests/test_email.py` reported `90 passed, 0 failed` on `main` with the bug present. The
new block covers five prose forms, the four quoted-header forms that must still cut, and the two
ambiguous forms that must be kept:

```
# with the marker reverted to r"^\s*From:\s.+$"
98 passed, 7 failed
  FAIL en/`From:` prose keeps the request: the reported case Hi team,
  FAIL en/`From:` prose keeps the request: lowercase Hi,
  FAIL en/`From:` prose keeps the request: uppercase Hi,
  FAIL en/`From:` prose keeps the request: extra spacing Hi,
  FAIL en/`From:` prose keeps the request: mid-body Hello,
  FAIL en/bare `From:` with no header neighbour is kept: From: Name then To: Hi,
  FAIL en/bare `From:` with no header neighbour is kept: From: Name alone Hi,

# restored
105 passed, 0 failed
```

The four quoted-header positive controls stay green in both states, so the fix is not simply
"stop cutting on `From:`".

```
$ python tests/test_email.py                  105 passed, 0 failed   (90 before)
$ python tests/test_lang_guess.py             52 passed, 0 failed
$ python tests/test_router.py                 all routing tests passed
$ python tests/test_criteria.py               128 passed, 0 failed
$ python tests/test_packaging.py              all packaging tests passed
$ python -m ruff check laya/ --select=E9,F63,F7,F82,F401,F811 --line-length=120
All checks passed!
$ python -m compileall -q laya/ tests/
```

Known limitation: `From:` followed by an address but no other header line is treated as a quote
header and cut, because that is what an address on a `From:` line overwhelmingly is in an email
body. A caller who writes prose that literally begins `From: <someone@example.com>` loses that
line; I could not construct a realistic case where that is a request, and the quoted-header case
is the common one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants