final edits - #109
Conversation
There was a problem hiding this comment.
Pull request overview
Tightens AI safety/robustness around n8n structured responses by returning explicit refusal/clarification results instead of falling back to mock intent detection, and adds parameter-clarification guards before executing genre/profile-based actions.
Changes:
- Update n8n response validation to return a safe refusal for unknown intents and a safe clarification for malformed structured payloads.
- Add “missing required parameter” clarification branches in
AiActionServicefor several genre/profile-driven intents. - Update/add unit tests to cover the new refusal/clarification behaviors.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/ai/providers/n8n-ai.provider.ts | Returns explicit refusal/clarification results for unknown/malformed n8n responses. |
| src/ai/ai.service.spec.ts | Updates n8n helper tests for new refusal behavior; adds malformed payload clarification test. |
| src/ai/ai-action.service.ts | Adds early clarification responses when required params (genre/profile/artist) are missing. |
| src/ai/ai-action.service.spec.ts | Adds test ensuring missing required n8n parameters do not execute playlist creation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -58,7 +58,14 @@ export function validateStructuredAiResponse(raw: unknown, message: string, cont | |||
| // Reject unknown or non-whitelisted intents | |||
| if (!intent || !(ALLOWED_INTENTS as readonly string[]).includes(intent)) { | |||
| logger.warn(`[N8N] Unknown intent "${intent}" — falling back to mock`); | |||
| const genre = this.cleanString(params.genre); | ||
| const limit = this.safeLimit(params.limit, 5); | ||
|
|
||
| if (!genre) { | ||
| return { | ||
| reply: 'Which genre should I search for?', | ||
| provider, | ||
| intent: 'recommend_by_genre', | ||
| actionsTaken: [], | ||
| needsConfirmation: true, | ||
| }; | ||
| } |
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Added the missing-genre test in commit 0aedcae. The test covers the recommend_by_genre missing-genre branch by asserting that:
- The response has
needsConfirmation: trueand the reply contains "genre" - Neither
prisma.track.findManynorprisma.genre.findManyare called (no DB queries executed)
Agent-Logs-Url: https://github.com/SWE-Team-9/Backend/sessions/ad00c089-b278-4a4c-8504-710d34fc133f Co-authored-by: MohanEhab <157999295+MohanEhab@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
No description provided.