[Tracker]
Update Summary: [One-line status update for stakeholders]
Short Description: Replace the custom provider/model selectors in the AI Validations FieldValidationRule plugins with the Provider Configuration Form Element, with default models enabled.
Check-in Date: MM/DD/YYYY
[/Tracker]
Problem/Motivation
The AI Validations module currently rolls its own provider/model selection UI in each FieldValidationRule plugin that doesn't allow for default model, making recipes hard. The AI module now ships a reusable Provider Configuration Form Element that handles this consistently, including default model selection. See AI Provider Configuration Form Element.
Proposed resolution
- Switch
AiTextConstraintFieldValidationRuleto the Provider Configuration Form Element. - Switch
AiImageConstraintFieldValidationRuleto the Provider Configuration Form Element. - Switch
AiImageClassificationConstraintFieldValidationRuleto the Provider Configuration Form Element. - Enable default models on the element so each rule falls back to the site's configured default.
AI usage (if applicable)
[x] AI Assisted Issue
This issue was generated with AI assistance, but was reviewed and refined by the creator.
[ ] AI Assisted Code
[ ] AI Generated Code
[ ] Vibe Coded
- This issue was created with the help of AI
Issue fork ai_validations-3586397
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ahmad-khalil-imagexComment #4
ahmad-khalil-imagexComment #5
marcus_johansson commentedReviewing
Comment #6
marcus_johansson commentedSome feedback there. One of them you can skip if you feel like it, the other ones should be done if I didn't missunderstand something.
I also wonder if we should set these rules to final, so we can be pretty lenient with changing them in the future. Less of an issue though.
Comment #7
ahmad-khalil-imagexComment #8
ahmad-khalil-imagexRefactored code as suggested.
Comment #9
marcus_johansson commentedThe code looks great, except for the cspell error. Setting back to needs work because of it, see: https://git.drupalcode.org/issue/ai_validations-3586397/-/jobs/9594252
I've set to needs testing before this can be merged - one example of how it can be tested is documented here: https://project.pages.drupalcode.org/ai/1.3.x/contribute/testing/full_pa...
An options is to write functional javascript tests.
Comment #10
ahmad-khalil-imagexFixed cspell error.
Comment #11
a.dmitriiev commentedAs per Marcus' comment, the functional javascript test is needed.
Comment #12
ahmad-khalil-imagexComment #13
ahmad-khalil-imagexAdded functional JavaScript test coverage for the Provider Configuration Form Element switch in
web/modules/contrib/ai/modules/ai_validations/tests/src/FunctionalJavascript/AiValidationsProviderConfigurationFormElementTest.php.5 tests, 53 assertions, all passing locally (Selenium 3, headless chromium, ~44s):
testTextRulePersistsSelectedProvider— adds anai_text_prompt_constraint_rulevia the UI, asserts theai_provider_configurationselect renders with the test provider/model option, saves, and verifies the rule'sdata.provideris persisted as theprovider__modelstring.testImageRulePersistsSelectedProvider— same flow againstai_image_constraint_rule(exercises thechat_with_image_visionpseudo-operation path).testImageClassificationRulePersistsSelectedModel— guards the legacymodelconfig key (vs.provider) against accidental renames onai_image_classificationconstraint_rule.testDefaultProviderOptionIsAvailableAndPersists— with a default provider configured for chat, asserts the "Default" option appears, selects it, and confirms an empty provider string is persisted (theuse_defaultpath).Test setup notes:
WebDriverTestBasewith the minimal profile (avoids a transient action-plugin discovery ordering when node is co-installed withai_test).ai_testmodule'sechoaiprovider withgpt-test— same fixture the AI module's ownAiProviderConfigurationElementTestuses.node:articlerule set, an image field exposed on the form display, and an admin user with administer field validation rule set + administer ai permissions insetUp().primeRuleFormFields()populates title + column BEFORE the provider is selected.On the manual Setup ai_validations walkthrough: I did not automate the end-to-end "Car Image Validation" scenario. The validator's XTRUE/XFALSE protocol is hard-coded as
str_contains($response->getText(), 'XTRUE'), and the documented prompt contains the literal stringXTRUE—ai_test'sEchoProviderechoes the prompt back, so the validator always passes regardless of the image. Reproducing the fail/pass round-trip would require either a custom test provider or a runtime-builtai_mock_provider_resultmatching the exact JSON-encodedChatInput(including base64 image bytes + runtime file id), which felt out of scope for this MR comment. Happy to add it as a follow-up if you'd like.Comment #15
abhisekmazumdarGood work on this MR, the switch to the Provider Configuration Form Element is clean and the functional JavaScript tests added in comment #12 are thorough.
Two small fixes have been added on top of the existing work:
1.
AiObjectDetectionConstraintValidatorwas not callingresolveProviderOption()The three rule plugins covered in the issue title (
ai_text_prompt_constraint_rule,ai_image_constraint_rule,ai_image_classification_constraint_rule) were already updated to callresolveProviderOption()on their validators, which enables the default-provider fallback. The object detection validator (AiObjectDetectionConstraintValidator) was missed, it was still reading$constraint->modeldirectly and passing it toloadProviderFromSimpleOption()without going through the base class method. This means the object detection rule could not fall back to the site's configured default provider, which contradicts the goal of the issue. The fix adds theresolveProviderOption()call to bring it in line with the other three validators.2. Added an explanatory comment on
$strictConfigSchema = FALSEin the test classThe reason for bypassing strict config schema validation was described in comment #12 (
field_validation.rule_set.*does not cover thedatasub-keys of individual rules), but it was not captured in the code. A doc comment has been added above the property so the next reader does not have to hunt through issue comments to understand why it is there.Keeping it in Needs Review for another round of eyes before RTBC.
AI disclosure: Code review, test analysis, and comment text were prepared with AI assistance and manually reviewed before posting.
Comment #16
marcus_johansson commentedI think this solves this: https://www.drupal.org/project/ai_validations/issues/3538581
Comment #17
abhisekmazumdarComment #18
abhisekmazumdarTested MR !3 on local Drupal 11 environment with OpenAI and EchoAI providers configured. All paths work as expected.
What I tested
ai_provider_configurationselect (not a plain text field). Selected OpenAI gpt-4o, saved, re-edited provider was pre-selected on reload. ✓modelkey (notprovider) as expected for backward compatibility. ✓resolveProviderOption()fix is in place: the validator no longer reads$constraint->modeldirectly. ✓Screenshots
Plan
I'm satisfied with the state of this MR. If anyone has objections or spots anything I've missed, please comment in the next few days otherwise I'll be merging this shortly.
This also resolves #3538581: Add possibility to add default models to AI Validations.
AI assisted (Claude Code): testing steps and comment drafted with AI assistance, all findings manually verified.
Comment #19
abhisekmazumdarAnd yes, the deprecated error for the field_validation module is fixed here: #3509056: PHP 8.4 implicit nullable deprecation
Next, I will create version 3.0.0-beta7 for field_validation, which will have the fixes and the warnings will be gone.
Comment #20
abhisekmazumdarComment #21
abhisekmazumdarMerged!!
Thanks to ahmad-khalil-imagex for the implementation and marcus_johansson for the thorough review. This also resolves #3538581: Add possibility to add default models to AI Validations.
Comment #24
ahmad-khalil-imagexCreated issue to tag a release for this: https://www.drupal.org/project/ai_validations/issues/3600260