validate_card
Validate Adaptive Card JSON against the v1.6 schema, returning diagnostics with suggested fixes for errors and checking host compatibility.
Instructions
Validate an Adaptive Card JSON against the v1.6 schema. Returns diagnostics with suggested fixes for each error. Accepts card JSON or a cardId from a previous tool call.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| card | Yes | The Adaptive Card JSON object to validate, or a cardId string | |
| host | No | Check compatibility with this host app. Default: generic | |
| strictMode | No | When true, warnings are treated as errors. Default: false |
Implementation Reference
- The handler function 'handleValidateCard' for the 'validate_card' tool. It performs schema validation, card analysis, accessibility checks, and host compatibility checks, returning a combined validation result.
export function handleValidateCard(input: ValidateCardInput): ValidationResult { const { card, host = "generic", strictMode = false } = input; // Schema validation const schemaResult = validateCard(card); // Card analysis const stats = analyzeCard(card); // Accessibility check const accessibility = checkAccessibility(card); // Host compatibility const hostCompatibility = checkHostCompatibility(card, host); // Structural best-practice checks const errors: ValidationError[] = [...schemaResult.errors]; // Enrich schema errors with suggested fixes for (const error of errors) { error.suggestedFix = getSuggestedFix(error); } // Check duplicate IDs const dupeIds = findDuplicateIds(card); for (const id of dupeIds) { errors.push({ path: `(id="${id}")`, message: `Duplicate element ID: "${id}"`, severity: "error", rule: "duplicate-id", suggestedFix: { description: `Rename one of the elements with id="${id}" to a unique value`, patch: { id: `${id}_2` }, }, }); } // Nesting depth warning if (stats.nestingDepth > 5) { errors.push({ path: "$.body", message: `Nesting depth is ${stats.nestingDepth} (recommended max: 5)`, severity: "warning", rule: "nesting-depth", suggestedFix: { description: "Use the transform_card tool with transform: 'flatten' to reduce nesting", }, }); } // Element count warning if (stats.elementCount > 50) { errors.push({ path: "$.body", message: `Card has ${stats.elementCount} elements (recommended max: 50)`, severity: "warning", rule: "element-count", suggestedFix: { description: "Use optimize_card with goals: ['performance', 'compact'] to reduce element count", }, }); } // Best practice: Action.Submit deprecation if (stats.actionTypes.includes("Action.Submit")) { errors.push({ path: "(actions)", message: "Consider using Action.Execute instead of Action.Submit for Universal Actions support", severity: "info", rule: "prefer-execute", suggestedFix: { description: "Use optimize_card with goals: ['modern'] to automatically replace Action.Submit with Action.Execute", }, }); } // Host compatibility as errors/warnings with suggested fixes for (const unsupported of hostCompatibility.unsupportedElements) { errors.push({ path: unsupported.path, message: unsupported.reason, severity: strictMode ? "error" : "warning", rule: "host-compatibility", suggestedFix: { description: `Use transform_card with transform: 'apply-host-config' and targetHost: '${host}' to auto-adapt`, }, }); } // Accessibility issue suggestions for (const issue of accessibility.issues) { const existingError = errors.find((e) => e.message === issue); if (!existingError) { errors.push({ path: extractPathFromIssue(issue), message: issue, severity: "info", rule: "accessibility", suggestedFix: { description: "Use optimize_card with goals: ['accessibility'] to auto-fix accessibility issues", }, }); } } const hasErrors = errors.some((e) => e.severity === "error"); const hasWarnings = errors.some((e) => e.severity === "warning"); return { valid: strictMode ? !hasErrors && !hasWarnings : !hasErrors, errors, accessibility, hostCompatibility, stats, }; }