Source bug fix - #2
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes several issues in voucher identification across the ingestion pipeline:
end_datestring type crash — When_merge_fields()updated an existing Event, date fields from the AI (ExtractedEvent.end_dateas ISO string like"2026-07-21") were set directly on the Event ORM model viasetattr(). The column isDateTime(timezone=True), causing PostgreSQL to reject the string value. This crashed every pipeline tick when an event was matched to an existing event.Over-aggressive AI prompt causing false positives — The system prompt instructed the LLM to mark study guides, forum discussions, podcasts, and general certification info as
is_voucher=trueif there was "even a hint" of a discount or voucher. This caused:False negatives on concrete discount offers — The Databricks "Advanced Learning Festival" post with a clear
"50% discount on any Databricks Certification"was classified asis_voucher=false, confidence=0by the AI.False positives on voucher storefronts — Pearson VUE pages that simply let you "buy a voucher" at full price (standard e-commerce, not a promotion) were being classified as promotional.
[null]in array fields causing parse errors — The AI occasionally returned"certifications": [null]or"regions": [null]instead ofnull, causing Pydantic validation failures.Type of Change
Affected Components
Testing
pytest— all 160 tests passruff check .— cleanruff format --check .— cleanmypy voucherbot tests— no new errorsAI Layer Changes
Changes Made
voucherbot/services/ai/schema.pymodel_validatorto stripNoneentries fromcertificationsandregionsarrays. The AI sometimes emits[null]instead ofnullor[], which caused Pydantic validation errors likeInput should be a valid string [type=string_type, input_value=None, input_type=NoneType]. Now[null]→None, and[null, "AZ-900", null]→["AZ-900"].voucherbot/services/ai/analyzer.py— System prompt rewritten:is_voucher=true/is_voucher=falsesections with concrete examples'50% off','save $100','20% discount on certification') placed at the top so the LLM recognizes explicit offers even within learning-event context"'Purchase vouchers', 'buy exam vouchers', 'order your voucher' — these are standard transactions, not promotions""earn"alone → not promotional;"earn rewards","earn discounts","earn vouchers","earn credits"→ promotional"exam credit","voucher credit"→ promotional;"CPE credits","CE credits","college credit"→ not promotionalvoucherbot/services/ingestion/event_matcher.py—_merge_fields():start_date/end_datefields beforesetattr(), matching the existing_parse_date()logic in_extracted_to_event_fields(). Preventsinvalid input for query argument $3: '2026-07-21' (expected a datetime.date or datetime.datetime instance, got 'str').voucherbot/providers/pearsonvue/collector.py—_PROMO_KEYWORDS:"voucher","save","sale","credit","promo","deal") with more specific promotional signals. Since Pearson is a certification voucher vendor, generic terms appear on nearly every page.Before / After
is_voucher=false,confidence=0is_voucher=true,confidence>0.7is_voucher=true("clear promotional intent")is_voucher=false(standard transaction)is_voucher=true("New certification voucher")is_voucher=false(no promotional offer)is_voucher=true("General certification info")is_voucher=false(no promotional offer)is_voucher=true("promotional intent detected")is_voucher=false(no promotional offer)DataError)datetime[null]in arraysnullAdditional Notes
The root cause of most false positives was the prompt instructing the LLM to treat study guides, learning paths, job postings, and news as
is_voucher=truewith low confidence if there was "even a hint" of a discount or voucher. The new prompt takes the opposite approach: it requires genuine promotional intent (discount amounts, free exam offers, coupon codes, giveaways, rewards programs) and explicitly lists non-promotional categories.The
end_datecrash was the most severe issue — it caused every pipeline tick to fail when the event matcher attempted to merge a date string into an existing event, preventing all downstream processing.