Enforcing Diagram Generation in AI Prompts

Sometimes, seemingly small changes can have a significant impact on the consistency and quality of AI-generated content. Recently, we encountered an issue in the devlog-ist/landing project where the Mermaid diagram generation was intermittently producing empty strings, despite being a crucial visual component.

The Problem

The initial AI prompt configuration defined the mermaid_diagram field as optional. While this provided flexibility, it also led to inconsistent outputs where the diagram was sometimes omitted, even when it was contextually relevant and necessary for illustrating the technical concepts discussed in the blog post. This inconsistency detracted from the overall user experience and reduced the effectiveness of the generated content.

The Solution

To address this, we modified the AI prompt schema to enforce diagram generation. Specifically, we changed the mermaid_diagram field from optional to required and added an explicit instruction: "do NOT leave empty". This ensures that the AI model must always attempt to generate a diagram, preventing empty strings from being returned.

{
  "mermaid_diagram": {
    "type": "string",
    "required": true,
    "description": "REQUIRED Mermaid diagram... Do NOT leave empty."
  }
}

By making diagram generation a mandatory part of the AI prompt, we ensure a more consistent and visually informative output for every generated blog post.

The Takeaway

Explicitly defining requirements and constraints in AI prompts is crucial for ensuring consistent and high-quality outputs. By marking the mermaid_diagram field as required and adding an explicit instruction to avoid empty strings, we significantly improved the reliability and visual appeal of our AI-generated content. Review your AI prompt schemas and ensure that all essential components are explicitly defined as required to maintain consistency and quality.

Enforcing Diagram Generation in AI Prompts
Gerardo Ruiz

Gerardo Ruiz

Author

Share: