LlmValidateText Function  
 
BOOL WINAPI LlmValidateText(
  LPCTSTR lpszMessageText,  
  INT cchMessageText  
);

The LlmValidateText function performs basic validation on text before it is submitted to a model.

Parameters

lpszMessageText
A pointer to the message text to validate. This parameter cannot be NULL.
cchMessageText
The number of characters in the message text, excluding the terminating null character. If this value is -1, the message text must be null-terminated and the entire string is checked.

Return Value

If the message text appears to be valid, the function returns non-zero. If the message text is empty, contains invalid characters, or appears to contain non-text data, the function returns zero. To get extended error information, call LlmGetLastError.

Remarks

The LlmValidateText function is intended to help applications detect invalid or malformed input before sending a request to a model. It checks for common problems such as empty strings, text that consists only of spaces or line breaks, illegal Unicode code points, non-printable characters, and input that appears to contain binary data. The message text cannot contain embedded null characters.

Applications that accept messages from users or other external sources should validate the text before submitting it to a model. This can help detect malformed or invalid input before a request is sent, reducing the chance of unexpected results or incurring unnecessary usage costs.

This function does not evaluate the quality, safety, or semantic meaning of the message. Although this function is most commonly used to check prompts sent to a model, it can be used to validate any type of text to ensure it is not malformed and contains printable characters.

There are two versions of this function. The wide character version of this function (LlmValidateTextW) validates the message text as UTF-16 Unicode. The ANSI version (LlmValidateTextA) first attempts to interpret the input as UTF-8 encoded text. If the input is not valid UTF-8, it attempts to convert the text to Unicode using the active code page and the resulting Unicode text is validated. The generic function name LlmValidateText automatically resolves to the ANSI or Unicode version based on whether the application is compiled with Unicode support.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csllmv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also

LlmEstimateTokenCount, LlmNormalizeText, LlmSendMessage, LlmSendMessageEx