PromptTextRedactor
Helpers & Utilities · AiDotNet.Evolution.Prompts
Strips terminal control sequences and credential-shaped text before it reaches a prompt or a log.
For Beginners
Programs print all sorts of things when they run, and some of it should not be
forwarded to an AI provider or written into a log: passwords, API keys, and invisible characters that can mess
up a terminal. This helper cleans that text first, replacing anything that looks like a secret with
<redacted>. You normally never call it yourself — the prompt builder runs everything through it
automatically — but it is available if you assemble prompts of your own.
How It Works
Everything a sandboxed program writes is untrusted: it is the output of code a model wrote, run against data the library did not choose. Quoting that output back into the next prompt is what makes a search converge, but it is also the path by which an API key printed into a stack trace, or an escape sequence that rewrites the operator’s terminal, would travel into a request body and a log file. This type is the single choke point that text passes through on its way into a prompt.
Redaction is conservative by design: it removes ANSI escape sequences and every other control character except tab and newline, and it replaces values shaped like bearer tokens, provider keys, and assignments to password-like or token-like names. It cannot recognise a secret that looks like ordinary prose, so it is a safety net rather than a guarantee — the primary defence remains not putting credentials where a sandboxed program can read them.
Methods
| Method | Summary |
|---|---|
string BoundToUtf8Bytes(string text, int maxBytes, bool wasTruncated) |
Truncates text so its UTF-8 encoding fits a byte budget without splitting a character. |
string FormatBytes(int bytes) |
Formats a byte count for a truncation notice using the invariant culture. |
string Redact(string text) |
Removes control sequences and credential-shaped values from text. |
string RedactAndBound(string text, int maxBytes, string truncationMarker, bool wasTruncated) |
Redacts text and truncates it to a byte budget, appending a marker when it was cut. |
Fields
| Field | Summary |
|---|---|
string RedactionMarker |
The text substituted for a value that looked like a credential. |