sanitizeForPrompt escapes user-provided text to prevent prompt injection. Wraps content in explicit data delimiters so the LLM treats it as data, not instructions.
(text string)
| 162 | // sanitizeForPrompt escapes user-provided text to prevent prompt injection. |
| 163 | // Wraps content in explicit data delimiters so the LLM treats it as data, not instructions. |
| 164 | func sanitizeForPrompt(text string) string { |
| 165 | if text == "" { |
| 166 | return "" |
| 167 | } |
| 168 | // Strip common prompt injection patterns |
| 169 | dangerous := []string{"<|im_start|>", "<|im_end|>", "<<SYS>>", "<</SYS>>", "[INST]", "[/INST]"} |
| 170 | result := text |
| 171 | for _, d := range dangerous { |
| 172 | result = strings.ReplaceAll(result, d, "[FILTERED]") |
| 173 | } |
| 174 | return result |
| 175 | } |
| 176 | |
| 177 | func buildAnalysisPrompt(req *pb.AnalyzeIssueRequest) string { |
| 178 | var sb strings.Builder |
no outgoing calls
no test coverage detected