Converting Craft Patterns to Logic Blocks
Given a raw pattern snippet, produce a structured logic block with explicit state variables, no narrative language, and numbered steps.
Input (raw pattern):
Rnd 4: *sc in next 2 sts, inc in next st, repeat from * around (24 sts)
Output (logic block):
JSON{ "round": 4, "starting_stitch_count": 18, "ending_stitch_count": 24, "repeat_unit": { "sequence": [ {"action": "sc", "count": 2}, {"action": "inc", "count": 1} ], "repeats": 6 }, "state_after": { "total_stitches": 24, "stitch_delta": 6 } }
Progress:
- Step 1: Ingest raw pattern text and identify craft type (crochet, knitting, cross-stitch, beadwork, sewing)
- Step 2: Extract all environmental variables (gauge, yarn weight, needle/hook size, fabric count, starting stitch/bead count)
- Step 3: Segment pattern into atomic instructions (rows/rounds/passes)
- Step 4: Resolve narrative/ambiguous language into explicit numeric actions
- Step 5: Compute state deltas (stitch count before/after, thread color changes, seam allowances)
- Step 6: Validate internal consistency (stated counts match computed counts)
- Step 7: Structure output into logic blocks with mobile-optimized formatting (short fields, no prose)
- Step 8: Flag unresolvable ambiguities for human review rather than guessing
Step Details
1. Identify craft type — Determines vocabulary and unit of repetition (stitch, row, bead, cut, seam).
2. Extract environmental variables — These are the "constants" that don't change per-instruction: gauge, tension, hook/needle size, fabric count (cross-stitch), thread/floss codes, seam allowance, garment size. Validate they're present; if missing, mark as "env_var_missing" rather than assuming a default.
3. Segment into atomic instructions — One logic block per row/round/pass. Never merge multiple rows into one block even if the source text does ("Rows 5-8: repeat Row 4").
4. Resolve narrative language — Replace phrases like "continue in pattern," "as established," "work even" with the literal repeated instruction, expanded in full or as an explicit repeat structure. Replace relative language ("a few more," "until desired length") with a required numeric input flagged as "user_defined".
5. Compute state deltas — Every block must report starting and ending counts (stitches, beads, panels). This is the core of "state tracking" — each block is a pure function: state_in -> instruction -> state_out.
6. Validate consistency — If the pattern states an ending count, verify it against your computed count. Mismatches get flagged, not silently corrected.
7. Structure for mobile — Use short key names, flat JSON where possible, avoid nested prose strings. Numeric fields as numbers, not words ("6" not "six").
8. Flag ambiguity — If a pattern cannot be resolved deterministically (e.g., "adjust as needed for gauge"), output a needs_human_input flag with the specific missing variable, rather than fabricating a value.
Example 1: Knitting Input:
Row 12: K1, *yo, k2tog; rep from * to last st, k1.
Output:
JSON{ "row": 12, "starting_stitch_count": 20, "ending_stitch_count": 20, "instructions": [ {"action": "k", "count": 1}, {"repeat": {"sequence": [{"action": "yo","count":1},{"action":"k2tog","count":1}], "times": 9}}, {"action": "k", "count": 1} ], "stitch_delta": 0 }
Example 2: Cross-stitch Input:
Stitch the border using DMC 815 in full cross stitch, then backstitch the outline with DMC 310 over 1.
Output:
JSON{ "pass": 1, "thread": "DMC 815", "stitch_type": "full_cross", "region": "border", "fabric_count_over": null, "flags": ["env_var_missing: fabric_count"] }, { "pass": 2, "thread": "DMC 310", "stitch_type": "backstitch", "fabric_count_over": 1, "region": "outline" }
Example 3: Sewing (ambiguity flagged) Input:
Sew side seams, then hem to desired length.
Output:
JSON{ "step": 3, "action": "sew_seam", "region": "side_seams", "seam_allowance_in": null, "flags": ["env_var_missing: seam_allowance"] }, { "step": 4, "action": "hem", "length_in": "user_defined", "flags": ["needs_human_input: desired_hem_length"] }
- Treat every instruction as a state transition: always report
count_inandcount_out. - Expand all repeats explicitly with
times/repeats— never leave "continue as established" unresolved. - Preserve one logic block per atomic unit of work (row, round, pass, seam) — don't collapse ranges.
- Convert all word-numbers and relative terms to numeric fields or explicit flags.
- Validate stated totals against computed totals; surface discrepancies rather than silently reconciling them.
- Keep schema flat and short-keyed for mobile rendering; avoid prose inside data fields.
- Separate environmental/global variables (gauge, fabric count, seam allowance) from per-step instructions.
- Do not guess a default gauge, fabric count, or seam allowance when it's missing — flag it.
- Do not merge multi-row/round instructions ("rows 5–8: repeat") into a single block; expand each one.
- Do not leave narrative phrases ("work even," "as desired," "adjust to fit") untranslated — they must become explicit numeric fields or human-input flags.
- Do not silently correct a mismatch between stated and computed stitch/bead counts — report it.
- Do not embed instructions as free-text sentences inside JSON values; decompose into discrete action/count pairs.