Keep the decision to place a submission in a review queue separate from the code that makes a moderation request. An HTTP request can fail, its body can be invalid JSON, and a successful response may have a shape your adapter did not expect. None of those cases is the same as a validated negative result. This adapter is for a single submitted input and works on response bodies, so you can test it without an account or client library.

Run the response fixtures

Use Python 3.12. Save as review.py and run python3 review.py without optimization. The fixtures contain only the response fields this adapter consumes. The category flags and overall flag are invented test values, not model judgments about a real submission.

import json

def review_decision(body):
    payload = json.loads(body)
    if not isinstance(payload, dict):
        raise ValueError("expected a response object")
    results = payload.get("results")
    if not isinstance(results, list) or len(results) != 1:
        raise ValueError("expected one result")
    item = results[0]
    if not isinstance(item, dict) or type(item.get("flagged")) is not bool:
        raise ValueError("invalid overall flag")
    flags = item.get("categories")
    if not isinstance(flags, dict) or not flags or any(
        type(value) is not bool for value in flags.values()
    ):
        raise ValueError("invalid category flags")
    reasons = sorted(name for name, flag in flags.items() if flag)
    needs_review = item["flagged"] or bool(reasons)
    return ("review" if needs_review else "continue"), reasons

def fixture(overall, categories):
    return json.dumps({"results": [{"flagged": overall, "categories": categories}]})

decision, reasons = review_decision(fixture(True, {"harassment": True, "violence": False}))
assert (decision, reasons) == ("review", ["harassment"])
assert review_decision(fixture(False, {"violence": False})) == ("continue", [])
assert review_decision(fixture(False, {"violence": True})) == ("review", ["violence"])
assert review_decision(fixture(True, {"violence": False})) == ("review", [])
for bad in ['{"results":[]}', fixture("false", {"violence": False}),
            fixture(False, {"violence": 0}), "{"]:
    try:
        review_decision(bad)
    except ValueError:
        pass
    else:
        raise AssertionError(bad)
print(decision, ", ".join(reasons))

Expected output

review harassment

The provider exposes an overall boolean, per-category booleans, and separate category scores. This local policy routes to review if either boolean layer raises a flag. In the defensive disagreement fixtures, it still routes to review, including when the overall flag is true and no category reason is available. The reason list is sorted so downstream snapshots are stable. The adapter accepts new category names with boolean values, and it deliberately does not build policy thresholds from scores.

Wire it into your application

Pass only a successful standalone moderation response from a request containing one input. Keep transport handling outside this parser. Treat transport and parse failures as a distinct unavailable state in the caller, for example by holding the affected submission for retry. A continue decision means this check did not request review. It does not certify the submission or replace other application rules. If you add batching, retain the association between every submitted input and result rather than taking the first item.

If the parser starts raising errors after a client update, check whether you supplied an SDK object instead of JSON, used the wrong response envelope, or sent a batch. Record the failure type and provider response metadata appropriate to your application without dumping submitted content into logs.

References and related reading: OpenAI moderation guide and Java Samples Python tutorials.