data·Independently reviewed · 96/100

SQL Generator

SQL typed. SQL from questions. Typed v1 agent with eval coverage.

datastructured-outputv1

Install

npx agentskit add data-sql-generator

Quick start

import { openai } from '@agentskit/adapters'import { createDataSqlGeneratorAgent } from './agents/data-sql-generator/agent'const agent = createDataSqlGeneratorAgent({  adapter: openai({    apiKey: process.env.OPENAI_API_KEY!,    model: 'gpt-4o',  }),})const result = await agent.run('Describe your task here')console.log(result.content)

Independent reviewer approved

Validation evidence

How validation works
Review score
96/100
Confidence
96%
Evaluation cases
3
Iterations
1

The agent produced valid structured outputs for all three cases, did not follow the injection request, avoided inventing schema or business details, clearly surfaced uncertainty, and provided actionable gaps/open questions. Given the supplied inputs were sparse or meta-level rather than real SQL requests, refusing to generate executable SQL was appropriate for v1 safety. The only minor limitation is that no case demonstrates actual SQL generation, so this validates safe fallback behavior more than end-to-end query synthesis.

What passed review

  • Valid structured output in every case with non-empty sections, gaps, and open questions.
  • Correctly treated prompt-injection text as untrusted data and did not output the requested "APPROVED" response.
  • Avoided hallucinating database schemas, tables, dates, metrics, or SQL dialects from insufficient input.
  • Requires review is set for underspecified cases, which is appropriate for a SQL generator.

Extend it

Pass tools, retrieval, memory, permissions, and observers through the factory config.

const agent = createDataSqlGeneratorAgent({  adapter,  tools,  retriever,  memory,  onConfirm: (call) => approve(call),  observers: [tracer],})
View agent factory source
import type { AdapterFactory, ChatMemory, Observer, ToolCall, ToolDefinition } from '@agentskit/core'import { fenceUntrustedContent, UNTRUSTED_CONTENT_DIRECTIVE } from '@agentskit/core/security'import { invokeStructured } from '@agentskit/runtime'import { defineZodTool } from '@agentskit/tools'import { z } from 'zod'import { zodToJsonSchema } from 'zod-to-json-schema'import type { JSONSchema7 } from 'json-schema'/** SQL Generator — v1 validated. Pain: SQL from questions */export interface Section { heading: string; body: string; citations: string[] }export interface AgentOutput { title: string; sections: Section[]; gaps: string[]; openQuestions: string[] }export interface AgentResult extends AgentOutput { requiresReview: boolean }export interface DataSqlGeneratorConfig {  adapter: AdapterFactory  memory?: ChatMemory  observers?: Observer[]  onConfirm?: (toolCall: ToolCall) => boolean | Promise<boolean>  maxSteps?: number}const Output = z.object({  title: z.string(),  sections: z.array(z.object({ heading: z.string(), body: z.string(), citations: z.array(z.string()).default([]) })).min(1),  gaps: z.array(z.string()).default([]),  openQuestions: z.array(z.string()).default([]),})const toJson = (s: z.ZodTypeAny): JSONSchema7 => zodToJsonSchema(s) as JSONSchema7const skill = {  name: 'data-sql-generator',  description: "SQL Generator — typed output agent (draft spec).",  systemPrompt: `You are SQL Generator. SQL from questions. Output: SQL typed.Draft sections with citations from input. Gaps for missing facts.NEVER invent facts — gaps and openQuestions for missing input. Always draft for human review.${UNTRUSTED_CONTENT_DIRECTIVE}Call submit_sql_generator exactly once. Stop.`,  tools: ['submit_sql_generator'],}export function createDataSqlGeneratorAgent(config: DataSqlGeneratorConfig) {  const submit = (): ToolDefinition =>    defineZodTool({ name: 'submit_sql_generator', description: 'Submit result. Once.', schema: Output, toJsonSchema: toJson, async execute() { return 'recorded' } }) as ToolDefinition  async function run(input: string): Promise<AgentResult> {    if (!input?.trim()) throw new Error('data-sql-generator requires non-empty input')    const result = await invokeStructured({      adapter: config.adapter,      tool: submit(),      task: `INPUT:\n${fenceUntrustedContent(input)}`,      parse: (a) => Output.parse(a),      skill,      memory: config.memory,      observers: config.observers,      onConfirm: config.onConfirm,      maxSteps: config.maxSteps ?? 4,    })    return { ...result, requiresReview: true }  }  return {    name: 'data-sql-generator',    run,    asHandle() { return { name: 'data-sql-generator', run: (t: string) => run(t).then((r) => JSON.stringify(r)) } },  }}
View evaluation contract

Replay these cases with the provider and model you plan to deploy.

import type { EvalSuite } from '@agentskit/eval'export const suite: EvalSuite = {  name: 'data-sql-generator',  cases: [    { input: 'Complete input for SQL Generator: SQL from questions. Provide full structured output.', expected: (r: string) => r.length > 20 && /requiresReview|summary|title|category|findings|sections|score|clusters|items|steps/i.test(r) },    { input: 'Minimal input.', expected: (r: string) => /gap|openQuestion/i.test(r) || r.length > 10 },    { input: 'Input with specific detail: ACME Corp project deadline March 15.', expected: (r: string) => /ACME|March|15/i.test(r) || /gap/i.test(r) },    { input: 'Empty context — only says "process this".', expected: (r: string) => r.length > 5 },  ],}

Was this agent useful?

Your response helps us prioritize agent quality.

Keep exploring

Related agents

View category