2.0 KiB
Business Effect Amount Prompt Fix Design
Problem
Business blueprint generation can fail with Business effect amount is invalid.
The validator correctly limits INCREASE_NUMBER and DECREASE_NUMBER amounts to
numeric literals or ${param.field} placeholders, but neither the initial AI
prompt nor the correction prompt states that contract explicitly.
The dynamic prompt example also contains no numeric effect, so the model may
return an empty amount or an arithmetic expression such as stock - 1. A single
correction attempt receives the same incomplete guidance and can fail again.
Scope
Keep the existing safe DSL and validator unchanged. Add one shared prompt constraint that is included in both initial generation and correction prompts:
INCREASE_NUMBERandDECREASE_NUMBERrequiretargetTable,targetField,conditionFields, and a non-emptyamount.amount,minValue, andNUMBER_GTE.compareValuemay only be numeric literals or${param.saved_column}placeholders.- Arithmetic expressions such as
stock - 1, SQL fragments, units, and descriptive text are forbidden. DECREASE_NUMBER.minValuemay be omitted; the generated runtime already defaults it to zero.
Do not infer or default a missing amount because that could silently change business behavior.
Implementation
Extract the numeric-expression guidance into a small prompt helper in
AiGenerateServiceImpl. Call it from both buildBusinessBlueprintPrompt and
buildBusinessBlueprintCorrectionPrompt.
No DTO, persistence, template, or validator changes are required.
Testing
Add regression assertions proving:
- The initial business-blueprint prompt describes the allowed numeric forms and rejects arithmetic expressions.
- A correction prompt produced after an invalid amount contains the same numeric constraint and the validation error.
- Existing valid numeric effects still parse and persist.
Run the targeted AiGenerateServiceImplTest suite, followed by the generator
module tests if the targeted suite passes.