If the function succeeds, the return value is the number of
characters copied to the output buffer, not including the terminating
null character. If the function fails, the return value is zero
and the LlmGetLastError function will return a non-zero value.
The LlmNormalizeText function processes the input string,
decomposing Unicode characters to their canonical equivalents, replacing
confusable homoglyphs with normalized characters, removing combining
characters, normalizing end-of-line characters, and trimming leading
and trailing whitespace including non-breaking spaces and other special
Unicode space characters. Although removing unnecessary whitespace may
slightly reduce token usage, the primary benefit is producing cleaner
and more consistent input for the model to process.
Line break characters are normalized to use Windows end-of-line conventions.
Isolated carriage return or line feed characters, Unicode line and paragraph
separators, and form feed characters are converted to CRLF sequences.
Multiple consecutive line breaks are reduced to improve consistency.
Normalization can be useful when comparing prompts, checking for empty or
whitespace-only input, or applying simple validation rules before a request
is submitted. It does not attempt to determine whether the text is safe,
appropriate, or semantically valid. Applications should perform any additional
validation required for their own use case.
Using this function is optional. Prompt text does not need to be normalized
before it is sent to a provider, and using this function is not a required
sanitization step. If preserving the exact formatting of the original text
is important, such as indentation, tables, or code samples, the application
should send the original text instead.
The ANSI version of this function expects the input to be UTF-8
encoded, but will fall back to using the current active code page if
invalid UTF-8 characters are encountered in the string. The output
from this function will always be valid Unicode text. For applications
using the ANSI version of this function, this means the output string
will use UTF-8 encoding.