Skip to content

fix(model)!: match literal stop sequences - #406

Merged
WH-2099 merged 1 commit into
mainfrom
fix/match-literal-stop-sequences
Oct 21, 2026
Merged

WH-2099 merged 1 commit into
mainfrom
fix/match-literal-stop-sequences

Conversation

@WH-2099

@WH-2099 WH-2099 commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Delivery status — 2026-11-02

Merged on 2026-10-21.
The fix is included in the planned SDK 0.11.0 release for Dify 1.19.0, tracked in #413.
The public SDK remains 0.10.2; plugin delivery follows publication.

The public stop helper interpreted stop strings as regular expressions: a period could erase the entire answer, [END] matched individual letters, and an empty list also returned an empty answer.
Use literal string searches and return the prefix before the earliest match, regardless of stop-list order.

Closes #400.

Compatibility for SDK 0.11.0 (unreleased): stop strings are literal, including punctuation and backslashes.
An empty list or no match returns the full input; an empty string in the list still matches at the start.
Callers using regex patterns must migrate to actual stop text, for example r"\." to ".".
The README documents the change.

No production callers were found in this SDK or dify-official-plugins at f2d781136.
The Azure OpenAI plugin's existing stop helper already uses its own literal search.
External callers were not available to inspect.

Validation: just check, just test (1,479 passed), and just build.
The focused cases cover punctuation, backslashes, literal and actual newlines, ordinary stops, overlapping stops in either order, empty inputs, empty stop lists, and no matches.

Pull Request Checklist

Thank you for your contribution! Before submitting your PR, please make sure you have completed the following checks:

Compatibility Check

  • I have checked whether this change affects the backward compatibility of the plugin declared in README.md
  • I have checked whether this change affects the forward compatibility of the plugin declared in README.md
  • If this change introduces a breaking change, I have discussed it with the project maintainer and specified the release version in the README.md
  • I have described the compatibility impact and the corresponding version number in the PR description
  • I have checked whether the plugin version is updated in the README.md

The target release is documented as 0.11.0; maintainer discussion is pending review of this PR.

Available Checks

  • just build has passed
  • Relevant documentation has been updated (if necessary)

Copilot AI balanced review requested due to automatic review settings October 15, 2026 05:17
@WH-2099 WH-2099 self-assigned this Oct 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation satisfies the stated behavior, with focused regression coverage and clear compatibility documentation.

0 open findings

What changed in this PR

Updates the SDK’s public stop helper to match literal text rather than regular expressions.

Changes:

  • Returns the prefix before the earliest stop, regardless of list order.
  • Expands regression coverage for punctuation, backslashes, overlapping stops, and empty inputs.
  • Documents the SDK 0.11.0 compatibility change and migration guidance.
File Description
tests/​interfaces/​model/​test_llm_stop_tokens.py Tests literal matching and edge cases.
src/​dify_plugin/​interfaces/​model/​large_language_model.py Replaces regex splitting with literal searches.
README.md Documents behavior and migration requirements.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@WH-2099
WH-2099 merged commit a6c7642 into main Oct 21, 2026
8 checks passed
@WH-2099
WH-2099 deleted the fix/match-literal-stop-sequences branch October 21, 2026 04:57
@WH-2099 WH-2099 added this to the 1.19.0 milestone Nov 2, 2026
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.

fix(model): treat stop sequences as literal text

3 participants