Overview
The title_generation and metadata_generation agents fail with a YAML parsing error when the current layout context contains apostrophes (e.g. "team's expertise" in a component's text content).
The layout context is injected into the agent's prompt as YAML, but values containing apostrophes are not properly escaped/quoted.
Steps to reproduce:
1. Open Canvas editor
2. Add a component with text containing an apostrophe (e.g. "Our team's expertise")
3. Ask the AI to "Generate a title for this page"
4. YAML parsing error
Proposed resolution
Ensure layout context values are properly quoted/escaped when serialized to YAML before being passed to the title and metadata generation agents.
User interface changes
Issue fork canvas-3572865
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 #3
petar_basic commentedFixed by escaping single quotes in the layout and page_title token values before they get replaced into the default_information_tools YAML. Tested with components containing apostrophes — title and metadata generation now work correctly.
Comment #4
rakhimandhania commentedComment #5
rakhimandhania commentedComment #6
ajv009 commentedComment #7
ajv009 commentedReviewed and tested MR !587. The fix is correct and well scoped.
Verified locally on Drupal 11.3.5 + canvas 1.x-dev + ai_agents 1.2.3. Invoked the token hook directly with apostrophe-containing data and confirmed:
Our team's expertisegets escaped toOur team''s expertiseIt's a great daygets escaped toIt''s a great dayWithout the fix, Symfony YAML throws:
I also checked whether other tokens need the same treatment. Looking at the YAML config files for all six agents,
layoutandpage_titleare the only user-content tokens placed inside single-quoted YAML values (in the title_generation and metadata_generation agent configs). The other tokens either appear in block scalars (where apostrophes are harmless) or carry system values like entity_type/entity_id/UUIDs. So the fix covers exactly the right scope.One minor note:
page_descriptionis defined as a token but is not referenced in any current agent YAML config, so it is not affected. If it gets used in single-quoted YAML context in the future, it would need the same escaping.Setting to RTBC.
Transparency note: This review was conducted with highly supervised usage of Claude Code. Not here to waste anyone's efforts or demean the work being done. I verified everything personally. If I'm not doing something right process-wise, please flag it.
Comment #9
akhil babuThanks for working on this. I have added the same check for the page_description token as well even though it's not used in the default information tool of any agents. Pushed a kernel test to validate the fix as well.
Comment #12
narendrarMerged. Thanks for working on this issue!
Comment #14
neha_bawankar commentedScenario
Result
Expected Result