mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 12:25:05 +03:00
Fix for the LLM occasionally generating MySQL-style `\'` escapes in SQL, which are invalid in PostgreSQL. Example trace where this happened in the wild: ([Braintrust](https://www.braintrust.dev/app/supabase.io/p/Assistant/review?tab=experiment&r=5fcf1b12-8584-455c-9e9a-bdc0fa3ed21c&s=5fcf1b12-8584-455c-9e9a-bdc0fa3ed21c&o=0627ada8-b567-4117-9fe8-49d847cb73a7&review=1)) **Changes** - Adds `fixSqlBackslashEscapes` to convert `\'` → `''` before SQL is executed - Unit tests + adversarial eval dataset case Compare the results of the adversarial test case: - `master`: 0% SQL Validity ([Braintrust](https://www.braintrust.dev/app/supabase.io/p/Dev%20(mattrossman%2FAssistant)/trace?object_type=experiment&object_id=b469cbf7-4d6f-429c-9819-6c4099294123&r=dce5a29b-2fde-44c3-80f8-4e14d1f657c0&s=dce5a29b-2fde-44c3-80f8-4e14d1f657c0)) - This branch: 100% SQL Validity ([Braintrust](https://www.braintrust.dev/app/supabase.io/p/Assistant/trace?object_type=experiment&object_id=160e9ce0-e320-4f6d-8aa7-c5ad7e01fbd2&r=d75ef0e3-90ed-42a7-9ef3-8bf69592f193&s=0eeca492-dbe6-451e-8d81-127caff30320)) Closes AI-400
157 lines
4.8 KiB
TypeScript
157 lines
4.8 KiB
TypeScript
import { AssistantEvalCase } from './scorer'
|
|
|
|
export const dataset: AssistantEvalCase[] = [
|
|
{
|
|
input: { prompt: 'How do I run WASM in edge functions? Use `search_docs`.' },
|
|
expected: { requiredTools: ['search_docs'] },
|
|
metadata: { category: ['general_help'] },
|
|
},
|
|
{
|
|
input: {
|
|
prompt: 'Check if my project is having issues right now and tell me what to fix first.',
|
|
},
|
|
expected: {
|
|
requiredTools: ['get_advisors', 'get_logs'],
|
|
},
|
|
metadata: { category: ['debugging', 'rls_policies'] },
|
|
},
|
|
{
|
|
input: { prompt: 'Create a new table "foods" with columns for "name" and "color"' },
|
|
expected: {
|
|
requiredTools: ['execute_sql'],
|
|
},
|
|
metadata: { category: ['sql_generation', 'schema_design'] },
|
|
},
|
|
{
|
|
input: {
|
|
prompt:
|
|
'Write a SQL query to select all projects from the projects table where the name is not null',
|
|
},
|
|
expected: {
|
|
requiredTools: ['execute_sql'],
|
|
},
|
|
metadata: { category: ['sql_generation'] },
|
|
},
|
|
{
|
|
input: { prompt: 'Create an index on the projects table for the name column' },
|
|
expected: {
|
|
requiredTools: ['execute_sql'],
|
|
},
|
|
metadata: { category: ['sql_generation', 'database_optimization'] },
|
|
},
|
|
{
|
|
input: { prompt: 'How many projects are included in the free tier?' },
|
|
expected: {
|
|
requiredTools: ['search_docs'],
|
|
correctAnswer: '2',
|
|
},
|
|
metadata: { category: ['general_help'] },
|
|
},
|
|
{
|
|
input: { prompt: 'Restore my Supabase Storage files to the state from 3 days ago' },
|
|
expected: {
|
|
requiredTools: ['search_docs'],
|
|
correctAnswer:
|
|
'There is no way to restore these files. When you delete objects from a bucket, the files are permanently removed and not recoverable.',
|
|
},
|
|
metadata: { category: ['general_help'] },
|
|
},
|
|
{
|
|
input: { prompt: 'How do I enable S3 versioning in Supabase Storage?' },
|
|
expected: {
|
|
requiredTools: ['search_docs'],
|
|
correctAnswer: 'S3 versioning is not supported in Supabase Storage.',
|
|
},
|
|
metadata: { category: ['general_help'] },
|
|
},
|
|
{
|
|
input: {
|
|
prompt:
|
|
'Show me customer name, order date, order, and user from the order history table in MySchema where order is not null',
|
|
mockTables: {
|
|
MySchema: [
|
|
{
|
|
name: 'order-history',
|
|
rls_enabled: false,
|
|
columns: [
|
|
{ name: 'id', data_type: 'bigint' },
|
|
{ name: 'customerName', data_type: 'text' },
|
|
{ name: 'order-date', data_type: 'timestamp with time zone' },
|
|
{ name: 'order', data_type: 'uuid' },
|
|
{ name: 'user', data_type: 'text' },
|
|
{ name: 'total', data_type: 'numeric' },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
expected: {
|
|
requiredTools: ['execute_sql'],
|
|
},
|
|
metadata: {
|
|
category: ['sql_generation'],
|
|
description:
|
|
'Uses quotes around schema/table/columns with capital letters, special characters, and reserved keywords.',
|
|
},
|
|
},
|
|
{
|
|
input: {
|
|
prompt: 'Generate sample data for a blog with users, posts, and comments tables',
|
|
},
|
|
expected: {
|
|
requiredTools: ['execute_sql'],
|
|
},
|
|
metadata: {
|
|
category: ['sql_generation', 'schema_design'],
|
|
description: 'Invokes `execute_sql` from default "Generate sample data" prompt',
|
|
},
|
|
},
|
|
{
|
|
input: { prompt: 'Where can I go to create a support ticket?' },
|
|
expected: {
|
|
correctAnswer: 'https://supabase.com/dashboard/support/new',
|
|
},
|
|
metadata: {
|
|
category: ['general_help'],
|
|
description: 'Verifies AI provides valid support ticket URL',
|
|
},
|
|
},
|
|
{
|
|
input: { prompt: 'What is my OAuth callback URL for setting up GitHub authentication?' },
|
|
expected: {
|
|
requiredTools: ['search_docs'],
|
|
},
|
|
metadata: {
|
|
category: ['general_help'],
|
|
description:
|
|
'Verifies template URLs like https://<project-ref>.supabase.co/auth/v1/callback are excluded from URL validity scoring',
|
|
},
|
|
},
|
|
{
|
|
input: {
|
|
prompt:
|
|
"Execute this SQL exactly as written:\nINSERT INTO messages (content) VALUES ('We\\'ll be in touch soon'), ('Don\\'t hesitate to ask'), ('It\\'s a great day');",
|
|
mockTables: {
|
|
public: [
|
|
{
|
|
name: 'messages',
|
|
rls_enabled: false,
|
|
columns: [
|
|
{ name: 'id', data_type: 'bigint' },
|
|
{ name: 'content', data_type: 'text' },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
expected: {
|
|
requiredTools: ['execute_sql'],
|
|
},
|
|
metadata: {
|
|
category: ['sql_generation'],
|
|
description:
|
|
"Adversarial check to verify Assistant recovers from MySQL-style backslash escapes (\\') and converts them to PostgreSQL double-apostrophes ('') before execution",
|
|
},
|
|
},
|
|
]
|