Objective: Transform raw CSV data into JSON schemas through LLM-generated scripts on AVM.

Data Transformation

Automate conversion pipelines by having an LLM produce transformation functions, then execute safely via AVM.

Scenario: Custom Schema Delivery

Clients request data in bespoke JSON structures without manual coding.

Solution: Schema-Driven Codegen

  1. Define Schema
    Provide a JSON Schema template.
  2. Generate Code
    Prompt the LLM to write an execute(input) function matching the schema.
  3. Secure Run
    Execute the function in AVM’s sandbox.
  4. Deliver Output
    Return parsed JSON conforming to the schema.

Example (TypeScript)

import { runPythonTool } from "@avm-ai/avm-vercel-ai";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";

const tool = runPythonTool();

async function transform(sample: string, schema: object) {
  const prompt = \`
Write execute(input) that transforms CSV in input["data"] to JSON
following this schema: \${JSON.stringify(schema)}\`;
  const { text: code } = await generateText({
    model: openai("gpt-4o"),
    prompt,
    tools: { runPython: tool },
  });
  const result = await tool.exec({ code, input: { data: sample } });
  return JSON.parse(result.output.result);
}

Next Steps

  • Validate output with JSON Schema tooling.
  • Chain pipelines in agent orchestrations.
  • Support additional runtimes for performance-critical tasks.