# Output Callbacks URL: /output-callbacks Learn how to create structured test results with OpenHTF, covering JSON output and custom output mechanisms with detailed examples. Enable automatic test report generation in JSON or other formats. Output callbacks run when a test ends and write its record somewhere: a JSON file by default, or anything you write. You can enable automatic test result export in the default JSON format. A `test_result.json` file is created after execution and saved in the execution directory. The pattern can use any field of the record, so one file per run is the usual choice: Format string expanded with the record's fields, a callable returning a path, or an open file object. Pretty-print indentation. `None` writes compact JSON. Default `True`: attachments are base64-encoded into the JSON. Set `False` to keep the file small when phases attach images or long logs. The general structure of an OpenHTF JSON record is as follows (full field list in the JSON format reference): `ConsoleSummary` prints the outcome and, on failure, every failed measurement with its value and validator. Useful while developing a test: Other built-ins: `callbacks.OutputToFile(pattern)` pickles the record, and `mfg_inspector.MfgInspector` converts it to Google's `TestRun` protobuf (`save_to_disk()` / `upload()`). Both live under `openhtf.output.callbacks`. Output callbacks run after every test, so that's where you send records to a database. Any REST API or database driver works with the custom callback pattern below. TofuPilot's client ships one: `upload()` doesn't retry: a failed upload is logged, not resent. Keep the JSON callback too if you can't lose a record. You can implement a custom output format by creating a function to handle the test record and adding it as an output callback if the built-in format doesn't meet your needs. Callbacks run in order after the test finishes. The output file will then be: On a station, the TofuPilot CLI uploads each run itself (no callback needed) and queues it on disk when the network is down.