Skip to content

fix(webllm): cleanRewriteLine should strip inline **verb** bold delimiters from rewrite output #152

Description

@Vaishnavi1709

Surfaced by

The eval harness from #65 (PR #149). Gemma 2 (2B) under the terse prompt variant emits per-bullet outputs that bold just the leading verb in markdown, e.g.:

**Increased** weekly active users by 1500% (120,000 to 1.8 million)…
**Spearheaded** a growth team of six individuals…
**Streamlined** the checkout process…

Example from tests/fixtures/rewrite/reports/eval-rewrite-gemma-2-2b-it-q4f16-1-mlc-…json:

{
  "text": "**Triaged** an average of 200+ inbound customer support tickets per week…",
  "startsWithActionVerb": false
}

The **Triaged** token survives into the bullet text. The first-token check in verbs.ts::startsWithActionVerb strips non-[a-z] chars after lowercasing, so the verb match itself still works — but the visible bullet contains literal ** delimiters that a user would see if this output were ever surfaced in product.

Root cause

src/lib/webllm/post-process.ts::cleanRewriteLine strips markdown emphasis only when the whole bullet is wrapped:

const withoutEmphasis = withoutPrefix
  .replace(/^\*\*(.+)\*\*$/s, "$1")
  .replace(/^\*(.+)\*$/s, "$1")
  .replace(/^_(.+)_$/s, "$1");

Inline **verb** at the start of a longer bullet doesn't match ^\*\*(.+)\*\*$, so the delimiters pass through.

Fix

Add a narrow pre-strip that removes **word** only when it leads the bullet (a verb-bolding pattern), without touching legitimate mid-line emphasis:

const withoutLeadingBold = trimmed.replace(/^\*\*([A-Za-z][\w-]*)\*\*\s+/, "$1 ");

Match characteristics:

  • ^\*\* — must be at the start
  • ([A-Za-z][\w-]*) — captured word (single token, alphanumeric/hyphen)
  • \*\*\s+ — closing delimiter followed by at least one space (so we only match when there's body text after)

Apply before the existing whole-bullet emphasis strip so the order is: leading-verb-bold strip → whole-bullet emphasis strip → list-marker strip → quote strip.

Add unit tests in post-process.test.ts:

expect(cleanRewriteLine("**Increased** weekly active users by 1500%."))
  .toBe("Increased weekly active users by 1500%.");
expect(cleanRewriteLine("**Streamlined the** checkout"))   // not just one word
  .toBe("**Streamlined the** checkout");                    // unchanged — defensive

Tracking

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

featureNew functionality

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions