# Business Blueprint Schema Repair Design ## Problem Business blueprint generation currently includes a fixed example that uses `book_info.book_id`. When the saved `book_info` table instead uses `id`, the model may copy the fixed example even though later prompt instructions list the real schema. Strict target-table validation then correctly rejects the generated condition field. ## Design Keep strict table-scoped validation unchanged. The generator must never infer that `book_id` means `id`, because those columns can have different meanings on different tables. Build the JSON shape example from the saved schema. Select the first table that has columns and use its primary key, or its first column when primary-key metadata is unavailable, as both the request field and an `EXISTS` rule condition. This keeps every identifier in the example valid for the current project while still demonstrating the expected DSL shape. If the first AI response fails business-blueprint validation, make one correction request. The correction prompt includes the validation error, the original response, and the saved table/column schema. Parse, normalize, and validate the corrected response through the same strict pipeline. A second invalid response is returned as the final error; there is no third attempt. ## Error Handling Only `ServiceException` raised while parsing, normalizing, or validating the AI business blueprint triggers correction. Authentication, project lookup, database loading, persistence, and network failures are not retried by this local correction path. Successful generation stores the final corrected AI response. Failed generation keeps the final validation error. Existing asynchronous retry behavior remains responsible for transient network failures. ## Testing Regression tests use a saved `book_info` table whose primary key is `id` while another table contains `book_id`. - The initial prompt example must use `book_info.id`, not `book_info.book_id`. - An invalid first response followed by a valid corrected response must result in two AI calls and persist the corrected blueprint. - Two invalid responses must still fail strict validation after exactly two AI calls.