Skip to content

Fix mislabeled proposal recommendations via structured crew output#29

Merged
therevoltingx merged 1 commit into
mainfrom
fix/proposal-recommendation-parsing
Jul 15, 2026
Merged

Fix mislabeled proposal recommendations via structured crew output#29
therevoltingx merged 1 commit into
mainfrom
fix/proposal-recommendation-parsing

Conversation

@Kishore-2572

Copy link
Copy Markdown

Fix mislabeled proposal recommendations via structured crew output

Problem: POST /proposals runs an AI crew to negotiate a proposal and returns its decision (accept/counter/reject) in the recommendation field. The code read this by scanning the AI's full text response for the word "accept" — but negotiation write-ups routinely contain that word elsewhere ("not acceptable as submitted", "Decision (Accept/Counter/Reject)"), so a real Counter decision was often reported as accept. Confirmed in 6 of 16 test cases, always in that direction — never the reverse.

Fix: the crew's final task now returns a typed, structured decision (via CrewAI's output_pydantic) instead of free text to scan. recommendation is read directly from that field, so there's nothing left to misparse. Also fixed a related bug in the same function — a blocking crew call from async code, which crashed silently and masked the AI's real decision behind a rule-based guess.

Verified: re-ran the previously-mislabeled case — now correctly reports counter instead of accept. No change to the response shape; recommendation still returns the same three values, just reliably now.

run_crew_evaluation() parsed the proposal-review crew's decision by
scanning its free-text output for the substring "accept" before
"counter". Negotiation writeups routinely contain that substring
elsewhere ("not acceptable as submitted", "Decision (Accept/Counter/
Reject)"), so a real "Counter" decision was frequently mislabeled as
"accept" -- confirmed across 6 of 16 cases in a Gemini test matrix,
always in that direction, and reproduced independently on GPT-4o.

Adds ProposalDecision/ProposalReviewOutput (models/flow_state.py) and
wires them in as the crew's final task output_pydantic schema
(crews/inventory_crews.py), so the decision is read from a typed field
instead of grepped out of prose.

Also fixes crew.kickoff() -> await crew.kickoff_async() in the same
function: the sync call raises immediately when invoked from this
async context, which was silently caught and fell back to rule-based
evaluation -- a prerequisite for the crew ever actually running here.

Verified against real API calls: GPT-4o returns a clean
ProposalDecision.COUNTER directly, and re-running gemini-2.5-flash's
previously-mislabeled below-floor scenario now correctly returns
Counter instead of the old parser's false Accept.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Kishore-2572
Kishore-2572 marked this pull request as ready for review July 10, 2026 15:56
@therevoltingx
therevoltingx merged commit a7c2dc7 into main Jul 15, 2026
2 checks passed
@therevoltingx
therevoltingx deleted the fix/proposal-recommendation-parsing branch July 15, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants