The Strategic Partner
The Strategic Partner helps the learner extend an existing implementation while protecting the requirements and behavior that already matter. Unlike earlier stages, the code alone is not enough: the mentor also needs the ticket context, acceptance criteria, expected behavior, and the learner’s current implementation so it can evaluate technical decisions against the actual business requirement.
- If the transaction amount is greater than $10,000, return
'High Risk'. - If the amount is greater than $5,000 OR (amount > $1,000 AND country is NOT
'US'), return'Medium Risk'. - If the amount is greater than $100 AND
new_accountisTrue, return'Low Risk'. - For all other cases, return
'Minimal Risk'.
The implementation below passes every transaction included with the ticket, but the learner notices that passing the sample data does not necessarily prove that the acceptance criteria are implemented correctly.
Txn T001 | Amount: $12,500.00 | Risk: High Risk Txn T002 | Amount: $ 6,000.00 | Risk: Medium Risk Txn T003 | Amount: $ 1,500.00 | Risk: Medium Risk Txn T004 | Amount: $ 800.00 | Risk: Low Risk Txn T005 | Amount: $ 50.00 | Risk: Minimal Risk
def evaluate_risk(transaction):
amount = transaction.get("amount", 0.0)
country = transaction.get("country", "US")
new_account = transaction.get("new_account", False)
if amount >= 10000:
return "High Risk"
elif amount >= 5000 or (amount >= 1000 and country != "US"):
return "Medium Risk"
elif amount >= 100 and new_account:
return "Low Risk"
else:
return "Minimal Risk"
What happens next? When you paste the ticket context, acceptance criteria, implementation, and strategic question immediately after the Mentor Prompt, you receive feedback like the example shown below.
Topic: Implement multi-way conditional decision paths using if, elif, and else.
We are shipping this to production, and I am thrilled you caught this before the PR was merged. In financial systems, “close enough” is how companies get fined by regulators. You are asking the exact right questions for a senior engineer.
To answer your questions directly:
-
The ticket explicitly says “greater than”. In legal/compliance logic, words are literal.
>is “greater than”,>=is “greater than or equal to”. If you use>=, an exact $10,000.00 transaction triggers High Risk. A strict reading of the ticket means exactly $10,000.00 should fall through to Medium Risk. -
Normalizing inputs (like calling
.upper()on a country code) is universally considered a safe, defensive implementation decision. Never trust the client to send perfectly cased data.
Let’s look at the broader system implications before we sign off.
Business Observations:
- Boundary Compliance: Your current implementation includes the boundary values in the higher risk tier. If compliance audits our system and finds a $10,000 transaction flagged as High Risk when the policy states “greater than $10,000”, that is a bug.
-
Data Integrity & Case Sensitivity: The API upstream might send
"us","US", or even"uS". Your currentcountry != "US"check will flag"us"as non-US, falsely elevating the risk of domestic transactions. -
Type Safety in Finance: You are currently defaulting to
0.0(a float). Financial systems should almost never use floating-point numbers due to precision loss (e.g.,0.1 + 0.2 != 0.3).
Socratic Question:
If a malicious actor or a front-end bug sends the amount as a string (e.g., {"amount": "15000", "country": "US"}), what happens when your code hits amount >= 10000? How can we harden the boundary checks so the system either coerces the type safely or fails predictably?
Next Step:
Before changing the operators, write three explicit unit tests for the exact values: 10000, 5000, and 100. Then, research Python’s decimal module for handling currency, and the string .upper().strip() methods to sanitize the country code.
Phase 2: Final Review
I will not rewrite the function for you—you already know what you need to do (swap >= for >, and add .upper() to the country string). Instead, let’s talk about how to make this logic truly ‘Production Ready’.
The Architect’s Verdict:
For financial decision trees, the code must be deterministic and mathematically precise. Moving forward, avoid using raw floats for currency. While Python’s if/elif/else branching is highly optimized and will scale beautifully under load, the data passing through those branches must be heavily sanitized. You should implement strict type hinting (e.g., using typing.Dict or typing.Mapping) and consider parsing the incoming payload with a schema validator before it even reaches this business logic.
Risk Assessment:
-
Type Mismatches: If the upstream service sends
amountas a string ("5000"), Python 3 will throw aTypeErrorwhen comparing it to an integer, causing a 500 Internal Server Error and failing the transaction entirely. -
Missing Keys & Defaults: You handled missing keys well with
.get(), but defaultingnew_accounttoFalsemeans if the upstream API drops that field, we default to the less secure assumption. In risk/security contexts, it’s often safer to fail closed (default to the higher risk state) than to fail open.
Recognition:
Excellent job utilizing .get() with fallback defaults, and fantastic work combining the Medium Risk checks into a single, clean elif branch using or and and. You avoided the trap of deeply nested if statements, keeping the cyclomatic complexity low and the readability high. This is clean, functional routing. Fix those operators, normalize the string, and ship it.
—
⚡ Coding5s Mentor System — Eliminating Epistemic Debt & Shipping to Production
