Skip to content

Self-describing instance/certificate formats; structured 400 on parse error#217

Open
wrigjl wants to merge 2 commits into
ReduxISU:CSharpAPIfrom
wrigjl:submit/problem-format-fields
Open

Self-describing instance/certificate formats; structured 400 on parse error#217
wrigjl wants to merge 2 commits into
ReduxISU:CSharpAPIfrom
wrigjl:submit/problem-format-fields

Conversation

@wrigjl
Copy link
Copy Markdown
Collaborator

@wrigjl wrigjl commented May 24, 2026

Adds two new fields to IProblem and turns parse failures on /verify and /problemInstance into structured 400 responses that quote the expected format back to the caller.

New fields on IProblem (default-implemented as "" so existing problems compile unchanged):

  • string instanceFormat — a short descriptive sentence with an embedded concrete example of the instance string the problem expects
  • string certificateFormat — same shape, but describes what the verifier accepts as a certificate

Populated on SAT3 and CLIQUE as a pilot. Other problems return empty strings until backfilled.

Two new exception types in Interfaces/ParseExceptions.cs:

  • ProblemParseException — thrown by a problem's instance constructor on malformed input. Carries the offending string.
  • CertificateParseException — thrown by a verifier on malformed certificate input. Carries the IProblem instance so the controller can read its certificateFormat.

SAT3 and CLIQUE constructors throw ProblemParseException on shape errors instead of silently constructing a half-populated problem object. SAT3Verifier and CliqueVerifier throw CertificateParseException instead of silently dropping malformed assignments (previously, lowercase 'true'/'false' in a SAT3 certificate would parse to an empty true-literal list and the verifier would just return false — no diagnostic).

IVerifier.verify default impl unwraps TargetInvocationException from Activator.CreateInstance so a ProblemParseException thrown from T(string) surfaces with its real type to the controller layer.

POST /ProblemProvider/verify and POST /ProblemProvider/problemInstance now return IActionResult. On parse failure they return HTTP 400 with body:

{ "error": "instance_parse_error" | "certificate_parse_error",
"problem": "",
"expected": "",
"received": "",
"detail": "" }

The "expected" field is the same string exposed by /ProblemProvider/info on instanceFormat/certificateFormat — single source of truth for the format hint. Success responses are unchanged (same JSON-string body, HTTP 200).

Verified live: the canonical SAT3 gut-check certificate "x1=true,x2=true,x3=false,x4=true" now returns 400 with the SAT3 certificateFormat in expected and "assignment 'x1=true' has value 'true'; expected True/False (capitalized) or T/F" in detail.

Backfilling the remaining ~41 problems and extending the validate-and-throw pattern to their verifiers is a natural follow-up.

…arse error

Adds `instanceFormat` and `certificateFormat` to `IProblem` with
default-empty implementations so existing problems compile unchanged.
Populates the fields on SAT3 and CLIQUE.

Introduces `ProblemParseException` and `CertificateParseException`.
SAT3 and CLIQUE constructors throw on malformed instances; SAT3Verifier
and CliqueVerifier throw instead of silently dropping malformed input.
`IVerifier<T>` default impl now unwraps `TargetInvocationException` so
parse exceptions surface with their real type to the controller.

`/ProblemProvider/verify` and `/ProblemProvider/problemInstance` now
return HTTP 400 with a structured body:

  { "error":    "instance_parse_error" | "certificate_parse_error",
    "problem":  "<problem name>",
    "expected": "<instanceFormat or certificateFormat verbatim>",
    "received": "<the offending input>",
    "detail":   "<specific reason>" }

The `expected` field comes from the same `instanceFormat`/
`certificateFormat` exposed by `/ProblemProvider/info` — single source
of truth for the format hint.

Backfilling the remaining ~41 problems and extending the
validate-and-throw pattern to their verifiers is the natural follow-up
(tracked in mcpredux TODO.md §1.5).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…ields

Adds instanceFormat / certificateFormat declarations with TODO
placeholders and inline examples to PROBLEM_Class.txt, and hints in
the string-instance constructor that bad inputs should throw
ProblemParseException so the controller layer can return a structured
400 instead of an unhandled-exception 500.

ProblemVerifier.txt gains a parallel hint in `verify`: throw
CertificateParseException on malformed certificate input rather than
silently returning false.

README.md documents both new fields under "Problem Class" and notes
the throw-on-parse-failure expectation under both "Problem Class" and
"Verifiers".

A generated template now nudges the contributor toward the
self-describing, structured-error pattern instead of the older
silent-failure default.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
wrigjl added a commit to wrigjl/Redux that referenced this pull request May 31, 2026
Ten reduction/verifier classes declared `private string _complexity = ""`
but never exposed it via a public property, producing CS0414 warnings and
silently omitting complexity from API responses. Replaced with:

    public string? complexity { get; set; } = null;

Null is an explicit "not specified" sentinel, giving callers a consistent
JSON shape. Also adds the property to the Reduction and Solver scaffolding
templates so new classes get it by default.

Remaining: KarpGraphColorToExactCover.cs and ProblemVerifier.txt are
blocked on PRs ReduxISU#215 and ReduxISU#217 respectively.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant