A clean script run is not a complete report. An AI client can write valid code, finish with zero errors, and hand you a crisp summary table that missed half your data.
Imagine a fictional alert platform that returns 100 records per page. Your agent pages through eight times, groups 800 alerts by company, and stops while more pages are still waiting. Every number in that table is accurate for the 800 records it saw, and completely wrong as an answer to "How many open alerts do we have?"
| Northwind | 412 |
| Contoso | 301 |
| Fabrikam | 87 |
| Total | 800 |
| Northwind | 412 |
| Contoso | 301 |
| Fabrikam | 87 |
| Read so far | 800 |
The fix is simple in principle and easy to forget in practice: make coverage part of the output, never an assumption.
Put the paging loop inside a script
Yapr's Code Mode gives your AI client one extra tool, stackyapper_run_code. Instead of pulling raw pages into the chat one turn at a time, the client writes a short JavaScript script that discovers read tools, loops through pages, aggregates the records, and returns only the summary.
In our alert example, the script keeps a running tally per company and hands back a few lines of JSON instead of 800 raw alert payloads. Keep one detail straight: the connected app still receives every API request, and every discovery or read call counts toward usage just like a direct call. When to use Code Mode covers when a script beats a single tool call.
Pair every count with its coverage status
A reader should never have to dig through logs to learn that a total stopped early. Put the count and its boundary in the same breath:
Alerts by company: Northwind 412, Contoso 301, Fabrikam 87. Read 800 records across 8 pages. Status: partial (more pages remain). Continue reading before treating this as a final total.
When a report combines multiple apps, give each source its own status label:
- Complete: the script covered the full requested scope and satisfied that app's documented end-of-list rule.
- Partial: more pages remain, or records were left out because of a cap.
- Unavailable: a read failed or timed out.
- Unknown: the app's response did not give enough information to prove completeness.
That distinction protects you from silent false reassurance. If the backup app timed out during a morning check, the report must say the backup source is unavailable. Printing "0 backup failures" turns a blind spot into a clean bill of health.
Plan your stop condition before looping
Code Mode runs inside clear boundaries for calls (up to 12 per run, including discovery), runtime (30 seconds), total data read (1 MiB), and returned output (64 KiB). Check the Code Mode limits reference and set a page cap before looping so the script finishes with room to explain what is left.
Do not assume every app pages the same way. Some use page numbers, some use opaque cursors, and some use snapshot tokens with an explicit completion rule. Always inspect the tool's schema first; a shorter-than-usual page only signals the end when that operation defines it that way.
If a run hits its page cap or budget before finishing, mark the source partial and carry forward a clean checkpoint in another run, keeping the exact connection, filters, and time window unchanged. If the scope is too wide for a couple of passes, break it into non-overlapping slices you can verify individually, and never add overlapping slices together.
Read-only still requires good boundaries
Code Mode runs with the signed-in person's current workspace permissions and rechecks access on every call inside the script. Create, update, delete, and execute tools are blocked before they reach the connected app, and reads that require explicit confirmation must run through the normal approval flow instead. The script has no direct access to the network, credentials, local files, or external packages.
Keeping scripts read-only stops a buggy loop from mutating production data, but it does not erase sensitivity. Who is allowed to read those records and where you paste the finished summary still matter.
On your next reporting prompt, ask the agent to return four fields alongside every metric: scope, records examined, completion status, and stop reason. If the status says partial, finish the remaining pages before anyone makes a decision from the total.