Asish Karthikeya Gogineni commited on
Commit
494f2e4
·
1 Parent(s): 31d220e

fix: Require explicit code citations in RAG responses

Browse files

- Updated prompt to require file paths + code snippets for every claim
- Added example format showing expected structure
- Ensures answers always include actual code from context

Files changed (1) hide show
  1. code_chatbot/prompts.py +22 -4
code_chatbot/prompts.py CHANGED
@@ -199,16 +199,34 @@ You have been provided with relevant code snippets retrieved from the codebase.
199
  - Prioritize accuracy over speculation - only discuss what you can verify from the code
200
 
201
  **OUTPUT FORMAT:**
202
- Provide your answer in well-structured markdown that a developer can immediately understand and act upon.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
 
204
  **CRITICAL RULES:**
205
  - **NO HTML**: Do NOT generate HTML tags. Use ONLY standard Markdown.
206
- - **NO UI MIMICRY**: Do NOT try to create "source chips" or other UI elements.
207
  - **NO HALLUCINATION**: ONLY discuss code that appears in the retrieved context above.
208
- - If the context does NOT contain relevant code, say: "I couldn't find code related to [topic] in the retrieved context. The codebase may not have this feature, or try asking about specific files or functions."
209
  - DO NOT make up generic explanations or describe how things "typically" work
210
  - DO NOT invent file paths, function names, or code
211
- - Be honest: if you don't see it in the context, don't pretend it exists
212
  """
213
 
214
  QUERY_EXPANSION_PROMPT = """Given a user question about a codebase, generate 3-5 diverse search queries optimized for semantic code search.
 
199
  - Prioritize accuracy over speculation - only discuss what you can verify from the code
200
 
201
  **OUTPUT FORMAT:**
202
+ Provide your answer in well-structured markdown. ALWAYS include:
203
+ 1. **File paths** for every file you reference (e.g., `src/main.py`)
204
+ 2. **Code snippets** - Quote actual code from the context in code blocks
205
+ 3. **Explanations** - Explain what the code does
206
+
207
+ Example format:
208
+ ```
209
+ ## Overview
210
+ [Brief answer]
211
+
212
+ ## Key Files
213
+ - `path/to/file.py` - [purpose]
214
+
215
+ ## Code Analysis
216
+ In `path/to/file.py`:
217
+ ```python
218
+ [actual code from context]
219
+ ```
220
+ This code [explanation]...
221
+ ```
222
 
223
  **CRITICAL RULES:**
224
  - **NO HTML**: Do NOT generate HTML tags. Use ONLY standard Markdown.
225
+ - **ALWAYS CITE CODE**: Every claim must be backed by a file path and code snippet from the context
226
  - **NO HALLUCINATION**: ONLY discuss code that appears in the retrieved context above.
227
+ - If the context does NOT contain relevant code, say: "I couldn't find code related to [topic] in the retrieved context."
228
  - DO NOT make up generic explanations or describe how things "typically" work
229
  - DO NOT invent file paths, function names, or code
 
230
  """
231
 
232
  QUERY_EXPANSION_PROMPT = """Given a user question about a codebase, generate 3-5 diverse search queries optimized for semantic code search.