mud_server.translation.validator
Output validator for the OOC→IC translation layer.
OutputValidator takes raw LLM text from the renderer and decides
whether it is suitable for storage as in-character dialogue. Unsuitable
output is rejected (returning None) so the caller can fall back to
the original OOC message.
Validation pipeline (applied in order)
Empty check — blank string →
None.PASSTHROUGH sentinel — the model signals that the OOC input has no meaningful IC equivalent (e.g. it was a command or meta-question). →
None.Multi-line check — strict mode rejects immediately; non-strict mode takes only the first non-empty line.
Quote stripping — some models (e.g. gemma2) consistently wrap output in
"..."or'...'; these are stripped before the forbidden-pattern check so that legitimate dialogue is not rejected purely because of quoting style.Forbidden pattern check — strict mode only. Rejects outputs that look like emotes, stage directions, or parenthetical narration. These indicate the model has not followed the “one line of raw dialogue” constraint.
Max-length enforcement — strict mode rejects; non-strict truncates.
Final empty check — returns
Noneif cleaning left an empty string.
Strict vs non-strict
strict_mode=True (the default) treats any constraint violation as a
hard rejection and returns None. This is the recommended setting for
production worlds because it guarantees that only well-formed IC dialogue
is ever stored — at the cost of occasionally falling back to OOC when
the model produces slightly imperfect output.
strict_mode=False makes a best-effort cleanup attempt for minor
violations (multi-line → first line; over-length → truncate). Useful
for low-stakes worlds or during prompt development.
Attributes
Classes
Validates and cleans raw LLM output before storage. |
Module Contents
- mud_server.translation.validator.logger
- mud_server.translation.validator.PASSTHROUGH_SENTINEL = 'PASSTHROUGH'
- class mud_server.translation.validator.OutputValidator(*, strict_mode, max_output_chars)[source]
Validates and cleans raw LLM output before storage.
- _strict_mode
When
True, any constraint violation →None.
- _max_output_chars
Hard ceiling on IC output character count.
Initialise the validator.
- Parameters: