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

Command icon 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

petar_basic created an issue. See original summary.

petar_basic’s picture

Status: Needs work » Needs review

Fixed 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.

rakhimandhania’s picture

rakhimandhania’s picture

Issue tags: +AI Page Generation
ajv009’s picture

Assigned: Unassigned » ajv009
ajv009’s picture

Assigned: ajv009 » Unassigned
Status: Needs review » Reviewed & tested by the community

Reviewed 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:

  1. Layout value Our team's expertise gets escaped to Our team''s expertise
  2. Page title It's a great day gets escaped to It''s a great day
  3. Both parse correctly as YAML single-quoted scalars and resolve back to the original strings with literal apostrophes

Without the fix, Symfony YAML throws:

Unexpected characters near "s expertise in building world-class solutions'" at line 1

I also checked whether other tokens need the same treatment. Looking at the YAML config files for all six agents, layout and page_title are 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_description is 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.

akhil babu made their first commit to this issue’s fork.

akhil babu’s picture

Thanks 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.

narendrar made their first commit to this issue’s fork.

narendrar’s picture

Status: Reviewed & tested by the community » Fixed

Merged. Thanks for working on this issue!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

neha_bawankar’s picture

Scenario

Result

Expected Result

  • Create new Canvas Page
  • Add a Text component
  • Enter the text: Our team
  • Prompt the AI: "Generate a catchy title and metadata for this page based on the content."
  • Generate Title : Meet Our Team: Built with Acquia Source
  • Generate Metadata : Meet our team! Discover the people behind our success. Built with Acquia Source to deliver exceptional digital experiences.
PASS
  • Create new Canvas Page
  • Add a Text component
  • Enter the text: Our team's expertise
  • Prompt the AI: "Generate a catchy title and metadata for this page based on the content."
  • Generate Title : Discover Our Team's Acquia Expertise and Digital Excellence
  • Generate Metadata : Discover how our team leverages Acquia's powerful platform to deliver exceptional digital experiences and showcase technical excellence in enterprise solutions.
PASS
  • Create new Canvas Page
  • Add a Text component
  • Enter the text: Our "team" expertise
  • Prompt the AI: "Generate a catchy title and metadata for this page based on the content."
  • Generate Title : Discover Solutions Built with Acquia Source
  • Generate Metadata : Discover our Acquia Source-powered platform with integrated search functionality and customizable content sections for your digital experience.
PASS
  • Create new Canvas Page
  • Add a Text component
  • Enter the text: 'Our team''s expertise'
  • Prompt the AI: "Generate a catchy title and metadata for this page based on the content."
  • Generate Title : Our Team's Expertise | Built with Acquia Source
  • Generate Metadata : Discover our team's expertise and solutions built with Acquia Source. Explore our capabilities and find what you need today.
PASS
  • Create new Canvas Page
  • Add title to page as - Test Page : 3572865
  • Publish the page
  • Add a Text component
  • Enter the text: 'Our team''s expertise'
  • Prompt the AI: "Generate a catchy title and metadata for this page based on the content."
  • Generate Title : Discover Our Team's Expertise with Acquia (Page title overwritten)
  • Generate Metadata : Discover our team's expertise and solutions built with Acquia Source. Explore innovative digital experiences and search our comprehensive resources.
PASS