dsh-sensitive-replace: Replace sensitive characters based on a masking table before outbound transmission to bypass DeepSeek official API 400 errors

Preface

When running agents in DeepSeek Harness (DSH), requests carry user input, tool results, historical messages, and system prompts. The DeepSeek official API returns Content Exists Risk type 400 errors for certain character combinations (common triggers include certain emoji code points appearing alone, which hit moderation). Such errors often only surface during long conversations or when tools feed back large amounts of external text, and post-hoc prompt modifications alone rarely provide a stable workaround.

The community already has plugins that neutralize by code point (e.g., dsh-text-guard). dsh-sensitive-replace takes a different path: you maintain a YAML blocklist, perform replacements before content enters the conversation context, and before the entire request goes out to the network; if a 400 still occurs, it can additionally perform hard cleaning and retry within the same session. Below we introduce the plugin’s positioning, the three gates, installation and blocklist formatting, as well as the boundaries you must accept when using it.

What Is This

dsh-sensitive-replace is a DSH Profile Bundle plugin maintained by Short-Arm-Ape (npm package name dsh-sensitive-replace, current documentation version v0.7.0, MIT license). In classification it belongs to model inference related capabilities: the goal is not PII redaction or “preventing the model from seeing a file,” but rather replacing characters/phrases that trigger official moderation, reducing INVALID_REQUEST / 400 errors, and maintaining conversation continuity as much as possible when something slips through.

The package declares dsh.bundle.patch in package.json; once installed into a profile it is automatically merged into cordis.patch.yml, and you generally do not need to hand-write plugin combination lines.

Core Features

Three Replacement Gates

The plugin works at three hooks, together covering content that is “newly entering the context” and “derived from logs and about to go out to the network”:

Gate Hook Effect
1 agent/pre-step User input, steering, and other messages before entering a step: returns a replaced copy of the message, preserving the message id, without rewriting the deep-frozen object in place
2 tools/post-execute Tool results (including nested blocks) such as web scraping, file reading, command output: replaced before being written to the session log
3 llm/stream Deep-copies and cleans the entire request before going out to the network: historical messages, model-written content, tool-call parameters, system, etc.

The first two gates occur before writing to the session log; when hit, the log permanently stores placeholders. The third gate only modifies the copy sent to the provider, and can compensate for content that was “already in the log before the plugin was installed”; DSH deep-freezes messages, so before going out to the network a copy must be made and then modified—you cannot modify options.messages in place.

400 Auto Recovery (recoverOn400)

If the blocklist does not cover the trigger and a 400 still occurs, the plugin at agent/request-error can: determine 400 / INVALID_REQUEST; temporarily add hard stripping of code points such as emoji/flags outside the rules (lasting aggressiveMs); return { kind:'retry' }, re-derive the request from the log and retry, without needing to rebuild the same session. The number of retries is capped by maxRecoveries and other configuration; you can also enable aggressive: true at all times for more aggressive code point stripping.

Rule Format and Operations

  • Blocklist default path: $DSH_HOME/sensitive-blocklist.yaml (default ~/.dsh), can be overridden via blocklistPath.
  • Supports global → Provider ID → model three-level chain; entries can be glyphs, \u{XXXX}, or re: regex.
  • Effective upon save: hot reload by file mtime; adding or removing words does not require restarting the profile.
  • Malformed blocklists will warn at load time, avoiding silent failures.
  • Read-only diagnostic tool sensitive_replace_status: rule count, cleaning counts per gate, rule hit statistics, format warnings, etc. (does not expose the full rule text).

Replacement is one-way and irreversible: gates 1/2 write placeholders into the log; gate 3 only modifies the outbound copy, so you may still see the original text on the interface while the model side sees placeholders. When post-hoc cross-referencing is needed, you can use replaceWith: '[BLOCKED:{n}]' and hits details for manual verification.

Installation and Activation

Prerequisites: dsh CLI on PATH, and determine the profile name (the example uses the default web).

When the registry is published:

dsh plugin --profile web add dsh-sensitive-replace

Or use a local build artifact:

dsh plugin --profile web add /abs/path/dsh-sensitive-replace-0.7.0.tgz

After installation, it is recommended to restart the profile (if the profile has patchReload: live enabled, changes to the patch layer can hot-apply, but it is still recommended to restart once when adding new dependencies).

Method 2: npm Dependency + Handwritten Patch Line

npm install /abs/path/dsh-sensitive-replace-0.7.0.tgz

Add the following to the user layer of the profile’s cordis.patch.yml:

- insert:
    - id: sensitive-replace
      name: 'dsh-sensitive-replace'

Prepare the Blocklist

Copy samples/sensitive-blocklist.example.yaml from the package to $DSH_HOME/sensitive-blocklist.yaml, and edit it according to your environment. It will auto-reload after saving.

Config Override Example

Override by id in the user patch layer (the user layer is after the bundle layer, so the latter takes effect):

- id: sensitive-replace
  config:
    enabled: true
    autoReplace: true
    detectUnfiltered: true
    blocklistPath: /abs/path/to/sensitive-blocklist.yaml
    replaceWith: '[BLOCKED]'

Typical Usage

Minimal Blocklist Example

Keys under providers must be DSH Provider routing ids (e.g., deepseek-official), not display names; writing the wrong one causes dedicated rules to not take effect.

# Sensitive character blocklist (supports comments)
global:
  - '\u{1F600}'             # Example: emoji code point, effective for all Providers
providers:
  deepseek-official: []     # Effective only for this Provider id

When subdividing by Provider / model, you can use providers.<id>.models.<model>; a trailing * on a key means prefix matching; in object form, base rules go under _. The README has complete three-level chain examples and common mistakes; it is recommended to cross-check before deployment.

Selection Compared to dsh-text-guard

Both can perform neutralization before writing to the log. This plugin additionally provides pre-network full request cleaning (including system and history), 400 same-session retry, YAML hot reload, and diagnostic tools. If you only need a zero-configuration code-point-level solution, dsh-text-guard is lighter; if you want a maintainable vocabulary + outbound fallback + 400 recovery, use this plugin. Mounting both generally does not conflict, but capabilities overlap, so usually just pick one.

Applicable Scenarios and Notes

Who it suits: Users who primarily go through the DeepSeek official API, are frequently interrupted by Content Exists Risk 400 errors; who want precise control over the replacement scope using a self-maintained blocklist, and need a final cleaning pass before tool results and long context go out to the network.

Must pay attention to:

  1. The plugin runs with the current DSH process privileges; before installation, please read the GitHub source and the MIT license to confirm it meets your security policy.
  2. Content not written into the blocklist will not be replaced by rules and remains a source of 400; recoverOn400 mainly strips code points such as emoji/symbols; curing the root cause still depends on completing the blocklist.
  3. If a rule matches JSON structural characters, it may change the semantics of tool-call parameters; rules should use content words, avoid writing structural fragments like "command".
  4. Binary attachments such as images/files do not participate in text replacement.
  5. Node engine requirement >=20; peer dependencies are the DSH ecosystem’s @deepseek-ai/cordis, dsh-tools, dsh-llm, etc., which must match the current DSH version (v0.7.0 states compatibility with DSH 0.2.0-rc.x).

The DSH community plugin directory is maintained by an independent site and has no official affiliation with DeepSeek / QuantumLeap; installation sources should be the npm package or a tarball you trust.

Conclusion

dsh-sensitive-replace connects “user YAML blocklist + three gates + optional 400 retry” into an operable chain, targeting 400 errors triggered by official API moderation, not general privacy redaction. If you repeatedly encounter Content Exists Risk in DSH, you can first install the plugin, configure $DSH_HOME/sensitive-blocklist.yaml, then use sensitive_replace_status to observe hits and warnings.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye