data_to_card
Convert structured data like JSON or CSV into optimized Adaptive Cards for Microsoft Teams, Outlook, and other platforms. Automatically selects or specifies presentation formats including tables, charts, lists, and facts.
Instructions
Convert structured data (JSON array, CSV, key-value object) into the optimal Adaptive Card presentation.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | Yes | The data to convert — JSON object, JSON array of objects, or CSV string | |
| presentation | No | Presentation type. "auto" (default) auto-selects | |
| title | No | Title for the card header | |
| host | No | Target host app. Default: generic | |
| templateMode | No | Generate a templated card with ${expression} data binding. Default: false |
Implementation Reference
- The handler function `handleDataToCard` is the main logic responsible for converting structured data into an Adaptive Card, utilizing LLMs for complex data or deterministic assembly for simpler cases.
export async function handleDataToCard( input: DataToCardInput, ): Promise<GenerateCardOutput> { const { data, presentation = "auto", title, host = "generic", theme, templateMode = false, } = input; const analysis = analyzeData(data); let card: Record<string, unknown>; let designNotes: string; // Try LLM for complex data structures if (isLLMAvailable() && (analysis.shape === "nested-object" || analysis.shape === "unknown")) { try { const systemPrompt = buildSystemPrompt(host); const userPrompt = buildDataToCardPrompt({ data, title, presentation, }); const response = await generateWithLLM({ systemPrompt, userPrompt, maxTokens: 4096, }); const parsed = extractJSON(response.content); if (parsed) { card = parsed; designNotes = `AI-generated from ${analysis.shape} data. ${analysis.summary}. Presentation: ${presentation === "auto" ? analysis.presentation : presentation}.`; } else { throw new Error("Failed to parse LLM output"); } } catch { // Fallback to deterministic card = assembleCard({ data, title, presentation, host, }); designNotes = `Deterministic generation from ${analysis.shape} data. ${analysis.summary}. Auto-selected: ${analysis.presentation}.`; } } else { // Deterministic generation card = assembleCard({ data, title, presentation, host, }); designNotes = `Generated from ${analysis.shape} data. ${analysis.summary}. Presentation: ${presentation === "auto" ? analysis.presentation : presentation}.`; } // Validate const validation = handleValidateCard({ card, host }); return { card, validation, designNotes, }; }