generate_and_validate
Generates an Adaptive Card from a natural language description, then validates it against the target host and optionally optimizes it—all in one call to reduce overhead.
Instructions
Generate an Adaptive Card and immediately validate + optionally optimize it in a single call. Reduces tool-call overhead for common workflows.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Natural language description of the card to generate | |
| data | No | Optional structured data to incorporate | |
| host | No | Target host app | |
| intent | No | Card intent | |
| version | No | Target version. Default: 1.6 | |
| optimizeGoals | No | If provided, also optimize the card after generation |
Implementation Reference
- packages/core/src/server.ts:581-639 (handler)The main handler function for the generate_and_validate tool. It calls handleGenerateCard, optionally optimizes via handleOptimizeCard, auto-downgrades version if needed, re-validates, and returns the result with cardId.
async function handleGenerateAndValidate( input: GenerateAndValidateInput, ): Promise<Record<string, unknown>> { const { content, data, host = "generic", intent, version = "1.6", optimizeGoals } = input; // Step 1: Generate const genResult = await handleGenerateCard({ content, data, host: host as HostApp, intent: intent as any, version, }); let card = genResult.card; let validation = genResult.validation; let designNotes = genResult.designNotes; const stepsCompleted = ["generate", "validate"]; // Step 2: Optimize if requested if (optimizeGoals && optimizeGoals.length > 0) { const optResult = handleOptimizeCard({ card, goals: optimizeGoals, host: host as HostApp, }); card = optResult.card; designNotes += ` | Optimized for: ${optimizeGoals.join(", ")}`; stepsCompleted.push("optimize"); } // Step 3: Auto-downgrade version if host requires it if (host !== "generic") { const hostInfo = getHostSupport(host as HostApp); const cardVersion = String(card.version || "1.6"); if (hostInfo && cardVersion > hostInfo.maxVersion) { const txResult = handleTransformCard({ card, transform: "downgrade-version", targetVersion: hostInfo.maxVersion, }); card = txResult.card; stepsCompleted.push("transform"); } } // Re-validate after all modifications validation = handleValidateCard({ card, host: host as HostApp }); const cardId = storeCard(card, { tool: "generate_and_validate" }); return { card, cardId, validation, stepsCompleted, designNotes, }; } - packages/core/src/server.ts:277-311 (schema)Input schema definition for the generate_and_validate tool, specifying content (required), data, host, intent, version, and optimizeGoals.
{ name: "generate_and_validate", description: "Generate an Adaptive Card and immediately validate + optionally optimize it in a single call. Reduces tool-call overhead for common workflows.", inputSchema: { type: "object" as const, properties: { content: { type: "string", description: "Natural language description of the card to generate", }, data: { description: "Optional structured data to incorporate", }, host: { type: "string", enum: HOST_ENUM, description: "Target host app" }, intent: { type: "string", enum: [ "display", "approval", "form", "notification", "dashboard", "report", "status", "profile", "list", "gallery", ], description: "Card intent", }, version: { type: "string", description: "Target version. Default: 1.6" }, optimizeGoals: { type: "array", items: { type: "string", enum: ["accessibility", "performance", "compact", "modern", "readability"], }, description: "If provided, also optimize the card after generation", }, }, required: ["content"], }, - TypeScript interface for GenerateAndValidateInput, defining the types for content, data, host, intent, version, and optimizeGoals.
export interface GenerateAndValidateInput { content: string; data?: Record<string, unknown> | string; host?: HostApp; intent?: CardIntent; version?: string; optimizeGoals?: OptimizationGoal[]; } - packages/core/src/server.ts:439-441 (registration)Switch-case in the tool dispatcher that routes 'generate_and_validate' tool calls to the handleGenerateAndValidate handler.
case "generate_and_validate": { result = await handleGenerateAndValidate(parsed as unknown as GenerateAndValidateInput); break; - Rate limiter configuration mapping tool names to bucket config; generate_and_validate uses the same LLM_TOOL_CONFIG as other LLM tools.
const toolConfigs = new Map<string, BucketConfig>([ ["generate_card", LLM_TOOL_CONFIG], ["data_to_card", LLM_TOOL_CONFIG], ["generate_and_validate", LLM_TOOL_CONFIG], ["card_workflow", LLM_TOOL_CONFIG], ]);