Commit 9814f13
fix: Prevent early returns with schema instructions (#292)
* fix: Prevent early returns when schema instructions are shown
Fixes issue where AI returns empty results immediately instead of
performing the requested analysis when schema is present in initial message.
## Problem
PR #291 added schema instructions to initial message to prevent JSON
validation loops. However, the example JSON (e.g., {"issues": []})
looked like a "completed" result, causing AI to return immediately
without doing the work.
## Root Cause
- Example showed empty arrays/default values
- For code review schemas, {"issues": []} looks like "no issues found"
- AI interpreted this as the expected immediate answer
- Result: Empty results on iteration 1 with no analysis
## Solution
1. Changed example label to clarify it's a FORMAT placeholder:
"Example:" → "Example format (populate with actual data...)"
2. Added explicit instruction to perform work first:
"You should still perform the requested analysis/task thoroughly
before providing the final JSON response."
3. Clarified schema purpose:
"The schema defines the format for your answer, not a shortcut
to return immediately."
## Impact
- Preserves JSON validation loop fix from #291
- Prevents premature returns with empty results
- AI now performs analysis before returning formatted JSON
- No breaking changes, backward compatible
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor: Remove example JSON from schema instructions
Following feedback, removed the example JSON entirely from schema
instructions. The schema definition itself is sufficient to show
the structure, and examples were causing confusion.
## Rationale
The example JSON (e.g., {"issues": []}) was:
- Looking like a "completed answer"
- Adding unnecessary tokens to every message
- Creating potential confusion between placeholder and expected result
The JSON schema definition already clearly shows:
- Field names and types
- Required vs optional fields
- Nested structure
- Validation constraints
This is sufficient for the AI to understand the format.
## Changes
- Removed generateExampleFromSchema() call from generateSchemaInstructions()
- Simplified instruction to: "First complete the requested analysis/task
thoroughly, then provide your final answer in the JSON format above."
- Cleaner, more direct, less ambiguous
## Benefits
- Eliminates risk of examples looking like expected answers
- Reduces token usage in initial messages
- Simpler, clearer communication
- Schema definition alone is sufficient
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor: Remove schema instructions from no-tool-call reminder
Schema instructions should only appear once at the beginning of the
conversation, not repeated in every "no tool call" reminder.
## Rationale
The original PR #291 added schema instructions in TWO places:
1. Initial user message (line 1462) - Good, sets expectations upfront
2. "No tool call" reminder (line 2023) - Bad, unnecessary repetition
This caused:
- Redundant schema information in conversation
- Extra tokens on every reminder
- Potential confusion from repetition
- Schema appearing in wrong context (when AI doesn't use tool)
## Solution
Remove schema instructions from the "no tool call" reminder. The schema
is already shown in the initial message, which is sufficient.
**Before:**
```javascript
if (options.schema) {
reminderContent = `Please use tools...` +
generateSchemaInstructions(options.schema, { debug: this.debug });
}
```
**After:**
```javascript
const reminderContent = `Please use tools...`;
// Schema was already shown in initial message
```
## Flow Now
1. User asks question with schema requirement
2. Initial message shows schema instructions ONCE ✅
3. AI works on the task
4. If AI doesn't use tool → standard reminder (no schema repetition)
5. When AI calls attempt_completion → validate against schema
6. If validation fails → correction prompt can remind about format
## Benefits
- Cleaner conversation flow
- Fewer tokens (schema not repeated in reminders)
- Schema shown once at the right time (beginning)
- Validation happens at the right time (when attempt_completion called)
- Less noise in the conversation
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* docs: Remove internal analysis document
This was just for internal analysis and shouldn't be in the PR
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 0afef33 commit 9814f13
2 files changed
Lines changed: 3 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2009 | 2009 | | |
2010 | 2010 | | |
2011 | 2011 | | |
2012 | | - | |
2013 | | - | |
2014 | | - | |
2015 | | - | |
2016 | | - | |
2017 | | - | |
2018 | | - | |
2019 | | - | |
2020 | | - | |
2021 | | - | |
2022 | | - | |
2023 | | - | |
2024 | | - | |
2025 | | - | |
2026 | | - | |
| 2012 | + | |
| 2013 | + | |
2027 | 2014 | | |
2028 | 2015 | | |
2029 | 2016 | | |
| |||
2035 | 2022 | | |
2036 | 2023 | | |
2037 | 2024 | | |
2038 | | - | |
2039 | 2025 | | |
2040 | 2026 | | |
2041 | 2027 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | 66 | | |
73 | 67 | | |
74 | 68 | | |
75 | 69 | | |
76 | 70 | | |
77 | 71 | | |
78 | 72 | | |
79 | | - | |
| 73 | + | |
80 | 74 | | |
81 | 75 | | |
82 | 76 | | |
| |||
0 commit comments