Number responses allow reviewers to input precise numeric values with customizable validation. They’re perfect for collecting prices, quantities, measurements, scores, or any numeric data that requires accuracy and consistency.
# Laboratory measurement verificationrequest_data = { "processing_type": "time-sensitive", "type": "markdown", "priority": "high", "request_text": "Verify the pH measurement reading from this laboratory test:\n\n**Sample:** Water Quality Test #WQ-2024-0847\n**Test Method:** Calibrated pH meter\n**Expected Range:** 6.5 - 8.5 (EPA drinking water standards)\n**Digital Reading:** 7.23\n**Lab Conditions:** 22°C, calibrated this morning\n\n**Quality Control:**\nPlease confirm the pH reading is accurate based on the sample color indicators and equipment calibration status shown in the attached documentation.\n\nNote: This is for regulatory compliance reporting.", "response_type": "number", "response_config": { "min_value": 0.0, "max_value": 14.0, "decimal_places": 2, "allow_negative": False, "required": True }, "default_response": 7.0, # Neutral pH default "timeout_seconds": 7200, # 2 hours "platform": "api"}
Your application should validate received numbers:
Copy
def validate_number_response(response_data, response_config): """Validate number response against configuration""" if not isinstance(response_data, (int, float)): return False, "Response must be a number" number = response_data # Validate numeric type (already done above) # number = response_data (simplified format) # Check range bounds min_value = response_config.get("min_value", 0) max_value = response_config["max_value"] if number < min_value: return False, f"Value must be at least {min_value}" if number > max_value: return False, f"Value cannot exceed {max_value}" # Check negative values allow_negative = response_config.get("allow_negative", False) if not allow_negative and number < 0: return False, "Negative values are not allowed" # Check decimal places decimal_places = response_config.get("decimal_places", 2) if decimal_places == 0 and number != int(number): return False, "Decimal values are not allowed" # Validate decimal precision decimal_str = str(number).split('.')[1] if '.' in str(number) else "" if len(decimal_str) > decimal_places: return False, f"Maximum {decimal_places} decimal places allowed" # Check required if response_config.get("required", False) and number is None: return False, "Number is required" return True, "Valid"# Usage exampleis_valid, error_message = validate_number_response( response_data=149.99, response_config={ "min_value": 50.00, "max_value": 500.00, "decimal_places": 2, "allow_negative": False, "required": True })
# Process numbers based on value rangesdef process_by_range(value, thresholds): """Apply different logic based on numeric ranges""" if value <= thresholds["low"]: return handle_low_value(value) elif value <= thresholds["medium"]: return handle_medium_value(value) elif value <= thresholds["high"]: return handle_high_value(value) else: return handle_extreme_value(value)# Usageprice_thresholds = {"low": 50, "medium": 100, "high": 200}inventory_thresholds = {"low": 10, "medium": 50, "high": 100}
Precision Handling
Copy
# Handle floating point precision properlyimport decimaldef process_financial_number(number_response): """Process financial numbers with proper precision""" # Convert to Decimal for precise financial calculations amount = decimal.Decimal(str(number_response)) # Round to appropriate precision rounded_amount = amount.quantize(decimal.Decimal('0.01')) return { "amount": float(rounded_amount), "cents": int(rounded_amount * 100) # For API integrations }
Comparative Analysis
Copy
# Compare numbers against historical datadef analyze_number_vs_history(current_value, historical_values): """Compare current number against historical patterns""" if not historical_values: return {"comparison": "no_history"} avg_historical = sum(historical_values) / len(historical_values) std_dev = calculate_std_deviation(historical_values) # Calculate z-score z_score = (current_value - avg_historical) / std_dev if std_dev > 0 else 0 # Determine significance if abs(z_score) > 2: significance = "highly_unusual" elif abs(z_score) > 1: significance = "unusual" else: significance = "normal" return { "current": current_value, "historical_average": avg_historical, "z_score": z_score, "significance": significance, "percentile": calculate_percentile(current_value, historical_values) }
# Process multiple number responses togetherdef calculate_weighted_average(number_responses, weights=None): """Calculate weighted average from multiple number responses""" if not number_responses: return None numbers = [response["number"] for response in number_responses] if weights and len(weights) == len(numbers): weighted_sum = sum(n * w for n, w in zip(numbers, weights)) total_weight = sum(weights) return weighted_sum / total_weight if total_weight > 0 else None else: # Simple average if no weights provided return sum(numbers) / len(numbers)