Problem/Motivation
We right now rely on non-structured response with AI prompts and want to switch to structured response.
Caveat that OpenAI implementation is different from Anthropic and maybe also Gemini. The Drupal AI module version might have have a generic way to handle structure responses so we might want to wait for that.
Issue fork ai_migration-3566728
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
dmundraComment #3
dmundraComment #4
dmundraDocumentation links
Comment #5
dmundraSo I started looking at
src/Normalizer/jsonapi/AiMigrationSchemaNormalizer.phpas a way to format the schema to the OpenAI format in the documentation.I was able to add name, strict, and schema and wrap the schema in into that level. Here the first error I got after getting to a point where it accepted those values,
[error] Error invoking model response: Invalid schema for response_format 'ai-migration-schema': In context=('properties', 'data', 'properties', 'attributes', 'properties', 'field_post_content'), 'additionalProperties' is required to be supplied and to be false.So it appears that every object schemata creates will need to have additionalProperties added. So going to try that next.
Comment #7
dmundraGot this working today after doing some schema manipulation like:
Comment #8
dmundraQA steps to try both structured output for OpenAI, Anthropic, and Gemini but also structured output not set for the same AI.
Initial configuration:
ddev drush migrate:rollback simple_content_migrationddev drush crSteps for testing with structured_output set to true:
ddev drush migrate:import simple_content_migrationddev drush migrate:rollback simple_content_migrationddev drush crddev drush migrate:rollback simple_content_migrationddev drush crddev drush migrate:rollback simple_content_migrationRepeat the above but change structured_output line to false. Confirm the schema does continue to import when it sends it via system prompt.
Repeat both for complex_content_migration. Confirm the complex migration works with both structured_output and system prompt.
Comment #9
dmundraTesting structured_output true for simple_content_migration with my changes worked for OpenAI (gpt-5.1), Anthropic (claude-sonnet-4-5-20250929), and Gemini (gemini-2.5-flash). Albeit everytime I rolled back I got rollback error
Testing structured_output false for simple_content_migration worked for all models as well.
Only thing remaining is trying complex content migration. Additionally in the review, need to look at the error above and the mess of changes to the schema. I am now including more stuff in the schema and the AI is generating values for it which the migration is so far ignoring or probably a cause of the above error.
Comment #10
dmundraReview #3561971: Create validator for structured content to help with validation of the schema
Comment #11
dmundraThe StatementWrapperIterator error might be related to #3569316: Client connection ($clientConnection) must be of type object, null given when deleting a node
Comment #12
dmundraTesting this with complex_content_migration revealed a flaw which is trying to generate schema of an entity that references a child schema will generate the AI schema version for those child ones as well. So ya we need to figure out how to correctly handle recursive entity schema generation.
Comment #13
dmundraComment #14
dmundraTo dos:
* Revert all code in https://git.drupalcode.org/project/ai_migration/-/merge_requests/33
* Add another normalizer that take the generated schema from schemata to generate one for the AI schema. Try to do that in the current normalizer to handle the recursive case of entity referencing entities.
* Look for normalizer example for this AI schema in Symfony AI, Drupal AI module maybe other places that we can plug in.
Comment #15
dmundraFrom kducharm