AI Validations: TypeError: Drupal\ai\OperationType\Chat\ChatMessage::__construct(): Argument #2 ($text) must be of type string, null given
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3503052. --> Reported by: [vivek panicker](https://www.drupal.org/user/3540616) Related to !436 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>AITextValidation throws error when the field it is validating contains empty string.</p> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <p>- Enable and configure AI Text validation for a node text field<br> - Let the rule have default values<br> - Create a new content and leave the text field empty<br> - Save the content.<br> - You will see this error:</p> <pre>TypeError: Drupal\ai\OperationType\Chat\ChatMessage::__construct(): Argument #2 ($text) must be of type string, null given, called in /var/www/html/web/modules/contrib/ai/modules/ai_validations/src/Plugin/Validation/Constraint/AiTextConstraintValidator.php on line 58 in Drupal\ai\OperationType\Chat\ChatMessage-&gt;__construct() (line 47 of modules/contrib/ai/src/OperationType/Chat/ChatMessage.php).</pre><h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Validation checks should not run if empty is given, since the field might not be mandatory.</p> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <p>NA</p> <h3 id="summary-ui-changes">User interface changes</h3> <p>NA</p> <h3 id="summary-api-changes">API changes</h3> <p>NA</p> <h3 id="summary-data-model-changes">Data model changes</h3> <p>NA</p>
issue