Copied to Clipboard
The app calls Telnyx to list phone numbers, then analyzes up to the first 20 numbers.
For each number, it builds a small health payload. In the sample, the default metrics are intentionally simple:
{"calls":0,"complaints":0,"answer_rate":0.5,"number":"+12125551234"}
Then the app asks the model to return JSON like this:
{"risk_level":"warning","recommendation":"rotate","reasoning":"Answer rate is low and complaint activity is elevated"}
If the recommendation is rotate, the app records it in a rotation log.
That is important: this sample does not automatically swap live numbers. It logs the recommendation. In a real outbound system, rotation should usually include policy checks, campaign state, routing rules, and human approval.
Why This Is Useful
Number reputation is not a single flag.
It is usually a collection of signals:
- answer rates
- complaints
- opt-outs
- call volume
- campaign history
- carrier filtering signals
- recent routing behavior
A model is useful here when it is not asked to invent a decision from nothing. It is useful when it gets structured operational context and returns a constrained recommendation.
That makes the output easier to route into a dashboard, review queue, or outbound routing system.
Inspect the Health Report
After a scan, you can inspect current state:
curl http://localhost:5000/health-report
The response includes tracked numbers and recent rotation recommendations:
{"numbers":{"+12125551234":{"calls":0,"complaints":0,"answer_rate":0.5,"analysis":{"risk_level":"warning","recommendation":"rotate","reasoning":"Example reason"}}},"rotations":[]}
That structure gives you a starting point for a real number-health dashboard.
The Small Detail That Matters
The prompt asks the model to return only JSON, with no prose and no markdown fences.
The app still includes a helper to strip markdown fences and parse the JSON object. I like that pattern because AI app code should be defensive. Prompts help, but validation is what keeps the output usable as application state.
What I Would Add Next
For production, I would add:
- Real metrics from calls, messages, opt-outs, complaints, and campaign outcomes
- Persistent storage for number history
- Scheduled scans instead of manual scans
- Alerts for critical numbers
- Human approval before rotation or retirement
- Routing rules that remove risky numbers from active campaigns
- Warmup and cooldown policies
- Audit logs for every recommendation and action
The repo is also structured to be agent-readable. Your coding agent can inspect the README, API reference, guide, environment file, and app code, then help extend it. You can ask it to add scheduled scans, persistent metrics, tests, dashboards, or real routing integration.
Try It
Code:
https://github.com/team-telnyx/telnyx-code-examples/tree/main/number-reputation-monitor-auto-rotate-python
Telnyx AI skills and toolkits:
https://github.com/team-telnyx/ai
List Phone Numbers API:
https://developers.telnyx.com/api/numbers/list-phone-numbers
Telnyx AI Inference docs:
https://developers.telnyx.com/docs/inference
Chat Completions API:
https://developers.telnyx.com/api/inference/chat-completions
Telnyx Portal:
https://portal.telnyx.com/