From 55d85021fcffcd87ef1703f1316be66c724371d7 Mon Sep 17 00:00:00 2001 From: Josh Creek <8179928+jcreek@users.noreply.github.com> Date: Sat, 26 Apr 2025 14:48:10 +0100 Subject: [PATCH] feat(*): Prevent prompt injection --- src/lib/server/ai.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/lib/server/ai.ts b/src/lib/server/ai.ts index fbf0f9e..fdb9764 100644 --- a/src/lib/server/ai.ts +++ b/src/lib/server/ai.ts @@ -6,12 +6,18 @@ import type { OpenAIResponse } from '../utils/types'; export function buildGradingPrompt(submission: string, task: string): string { return `You are an expert secondary school teacher and AI assessment agent. Assess the following student submission in the context of the assignment/task provided. -TASK/ASSIGNMENT: +===== TASK/ASSIGNMENT possibly including rubric or available marks ===== + ${task} -STUDENT SUBMISSION: +===== END TASK/ASSIGNMENT ===== + +===== STUDENT SUBMISSION ===== + ${submission} +===== END STUDENT SUBMISSION ===== + Follow these steps: 1. Grade the work. Use whatever grading scheme is present in the rubric. If none is present then grade with a letter (A+ is best, E- is worst), using clear, objective criteria. DO NOT mention tool errors. 2. Identify specific strengths, referencing the success criteria. @@ -46,12 +52,19 @@ export function buildGradingPromptWithSupportForHumanInTheLoop( ): string { return `You are an expert secondary school teacher and AI assessment agent. Assess the following student submission in the context of the assignment/task provided. -TASK/ASSIGNMENT: + +===== TASK/ASSIGNMENT possibly including rubric or available marks ===== + ${task} -STUDENT SUBMISSION: +===== END TASK/ASSIGNMENT ===== + +===== STUDENT SUBMISSION ===== + ${submission} +===== END STUDENT SUBMISSION ===== + Follow these steps: 1. Grade the work. Use whatever grading scheme is present in the rubric. If none is present, grade with a letter (A+ is best, E- is worst), using clear, objective criteria. 2. Identify specific strengths, referencing the success criteria.