Skip to content

Work on a machine · Material 10 of 12

Run a local report script with your AI

Run one reviewed Python script against a small stock file, verify its new report, and handle an existing output without overwriting it.

Founder-led byMark KorotinFounder & CEO, CMDOP
onemark.cc

Run a known, locally installed report script through your connected AI. Give the script one approved input and a new output name, then check the result. In this exercise the script reports stock below a reorder point. It never places an order or changes inventory.

Prepare a disposable example

Choose an online Mac or Linux computer that you own, with Python 3 installed. Create an empty practice folder outside your real stock or accounting system. The following files are synthetic and contain no customer data. Save each under its stated name.

Save stock.csv:

sku,on_hand,reorder_point
CUP-01,4,10
BOX-02,12,8
TAPE-03,0,5
LABEL-04,6,6

Save stock_report.py:

import csv
import json
import sys

if len(sys.argv) != 3:
    raise SystemExit("Usage: stock_report.py INPUT.csv OUTPUT.json")

source, output = sys.argv[1:]
with open(source, encoding="utf-8", newline="") as f:
    rows = csv.DictReader(f)
    if rows.fieldnames != ["sku", "on_hand", "reorder_point"]:
        raise SystemExit("Unexpected CSV columns")
    report = []
    seen = set()
    for row in rows:
        sku = row["sku"]
        if not sku or sku in seen or None in row:
            raise SystemExit("Invalid or repeated SKU")
        seen.add(sku)
        try:
            current = int(row["on_hand"])
            threshold = int(row["reorder_point"])
        except (ValueError, TypeError):
            raise SystemExit("Invalid stock quantity")
        if current < 0 or threshold < 0:
            raise SystemExit("Invalid stock quantity")
        if current < threshold:
            report.append({"sku": sku, "shortfall": threshold - current})

try:
    with open(output, "x", encoding="utf-8") as f:
        json.dump({"items_below_threshold": len(report), "items": report}, f, indent=2)
        f.write("\n")
except FileExistsError:
    raise SystemExit("Output already exists; choose a new file")

print(f"Report written: {len(report)} items below threshold")

Read and understand the script before allowing execution. This is a small practice script, not an inventory management integration. In a real workflow, use the exact script and version already reviewed by its owner. Do not ask the AI to rewrite an existing production script, install software, or add side effects just to run a report.

Request one bounded run

Name the computer and the absolute path of the practice folder. The command execution permission must be explicitly enabled for the selected agent and allowed by the machine's ceiling. Use only the read and execution access needed for this exercise. Preparing the two files is a separate action; the agent does not need the file-write tool for the report run itself. Command execution can still write files according to the process's operating-system permissions.

Ask the agent:

Use only the selected computer and practice folder.
Read stock_report.py and stock.csv, and record their
SHA-256 hashes with fs_stat.
Verify the script and input are the approved example.
Run python3 once with these exact arguments:
stock_report.py stock.csv reorder-report.json
Use the practice folder as cwd.
Do not edit either input, install software, access the
network, or order stock. Check the exit status, then
read and verify the new report. If anything differs,
stop and explain rather than retrying automatically.

Use exec_run with an argument vector, not a generated shell pipeline. The executable and arguments correspond to this command:

python3 stock_report.py stock.csv reorder-report.json

The script validates the column names and quantities, refuses repeated SKUs, and opens the output with exclusive creation. Its shortfall is the difference between the stated threshold and current stock, not a forecast, purchase quantity recommendation or supplier order.

Verify the report

For the supplied fixture the command should exit with code zero. The terminal message alone is not enough: read the whole new JSON file, with no truncation, and check its contents. Use the task outcome verification checklist to distinguish a finished process from a verified result.

{
  "items_below_threshold": 2,
  "items": [
    {
      "sku": "CUP-01",
      "shortfall": 6
    },
    {
      "sku": "TAPE-03",
      "shortfall": 5
    }
  ]
}

The expected positions are CUP-01, six units below its threshold, and TAPE-03, five units below its threshold. BOX-02 and LABEL-04 are at or above their thresholds. Use fs_stat with hash enabled to compare the source file and script before and after execution.

In an actual controlled run on an enrolled Linux machine, the command returned exit code zero and the message Report written: 2 items below threshold. The resulting report was 165 bytes, read in full. The script and input SHA-256 values were unchanged.

Handle an existing result

Do not make a failed call into a blind retry. First check the existing output. If the call did not complete, see Diagnose an AI agent call that did not complete. If you intentionally repeat this same synthetic exercise with the same output name, the supplied script returns a non-zero exit code and refuses to overwrite the report.

In the controlled example, the second run returned exit code 1 and the message Output already exists; choose a new file. All three file hashes matched their earlier values. That refusal belongs to this script's exclusive file creation, not to an automatic rollback guarantee of exec_run.

For a real run, review partial or unexpected results before another execution. Use a different approved output name only when the owner actually wants a new report. A script may have side effects before it fails. Do not assume other scripts are safe to repeat, or that an existing output proves the latest job succeeded.

The output is a report for human review, not authority to change stock, contact suppliers, or purchase anything. Treat input data as data, keep the original files unchanged, and report denied access or an offline computer without switching machines.