Document business effect amount prompt fix

This commit is contained in:
王鹏
2026-06-18 16:44:25 +08:00
parent 566dddfa1b
commit 1df3edaeea

View File

@@ -0,0 +1,50 @@
# 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_NUMBER` and `DECREASE_NUMBER` require `targetTable`, `targetField`,
`conditionFields`, and a non-empty `amount`.
- `amount`, `minValue`, and `NUMBER_GTE.compareValue` may 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.minValue` may 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:
1. The initial business-blueprint prompt describes the allowed numeric forms
and rejects arithmetic expressions.
2. A correction prompt produced after an invalid amount contains the same
numeric constraint and the validation error.
3. Existing valid numeric effects still parse and persist.
Run the targeted `AiGenerateServiceImplTest` suite, followed by the generator
module tests if the targeted suite passes.