In this example you are just printing the error with a very expressive message, but you get the idea. You can use the exception and then just reuse the default exception handlers.
## Handling Low-Confidence Predictions in ML APIs
In machine learning-powered APIs, predictions may not always be reliable.
Instead of always returning a prediction, it can be useful to detect low-confidence outputs and notify the client explicitly.
This can be achieved using `HTTPException`.
### Example: Reject low-confidence predictions
In this example, the API simulates a prediction along with a confidence score.
If the confidence is below a defined threshold, the API raises an error instead of returning an unreliable prediction.