diff --git a/src/scripts/generate_openfisca_tests_yaml.ts b/src/scripts/generate_openfisca_tests_yaml.ts
index 369309bd45d5a0320c849beaf82bde356442f665..fae7ddefd727f1f9fc12e948ce6c5e656889b872 100644
--- a/src/scripts/generate_openfisca_tests_yaml.ts
+++ b/src/scripts/generate_openfisca_tests_yaml.ts
@@ -726,6 +726,47 @@ async function main() {
         console.error(error)
       }
     }
+
+    console.info("Adjusting max_spiral_loop")
+    while (ok && jsonForYamlOutput.max_spiral_loops > 1) {
+      jsonForYamlOutput.max_spiral_loops =
+        jsonForYamlOutput.max_spiral_loops - 1
+      const yamlOutput = YAML.dump(jsonForYamlOutput, {
+        noCompatMode: true,
+        noRefs: true,
+      })
+      const cleanedYaml = yamlOutput.replace(/'(\d{4})':/g, "$1:")
+
+      await fs.writeFile(path.join(outdir, testCase.id + ".yml"), cleanedYaml)
+
+      try {
+        const openFiscaTestResult = await runOpenFiscaTest(
+          openFiscaVenvPath,
+          path.join(outdir, testCase.id + ".yml"),
+        )
+        if (!openFiscaTestResult.passed) {
+          ok = false
+          jsonForYamlOutput.max_spiral_loops =
+            jsonForYamlOutput.max_spiral_loops + 1
+          const yamlOutput = YAML.dump(jsonForYamlOutput, {
+            noCompatMode: true,
+            noRefs: true,
+          })
+          const cleanedYaml = yamlOutput.replace(/'(\d{4})':/g, "$1:")
+
+          await fs.writeFile(
+            path.join(outdir, testCase.id + ".yml"),
+            cleanedYaml,
+          )
+          console.info("YAML file written :", outdir, testCase.id + ".yml")
+        } else {
+          ok = true
+        }
+      } catch (error) {
+        console.error(error)
+      }
+    }
+
     console.info("Processed test-case", processedCounter, "over", testCaseCount)
   }
 }