# Semantic String Debt LLM Audit Findings

- result chunks: `3`
- findings: `10`

## `backend/app/core/steps/render_prompt_card.py`

- `169-1496` **P2 / scenario_dependent_prompt**
  - evidence: _ID_ETHNICITY_COMPONENTS ... (e.g. 'An Asian man' / 'a woman' / 'a figure')
  - why: The system-level card templates contain concrete scenario pollution, specifically a bias towards 'Asian' demographics as the default or primary example for person descriptions. This biases the LLM's generation for arbitrary future scenarios that may not share this demographic context.
  - fix: Use abstract placeholders like [ethnicity] or [demographic_descriptor] in examples, and ensure the ethnicity vocabulary is either dynamically injected based on the project's visual world rules or remains strictly neutral.

- `582-1191` **P2 / llm_closed_list_instruction**
  - evidence: camera_direction specifies a vertical height/position (low / hip-height / overhead / ground level / quay level / floor level / from above) ... trigger_phrases: list(_ID_BODY_PART_TRIGGERS)
  - why: The prompt card offloads semantic classification of visual framing and focus to the LLM using closed keyword lists. This is brittle because it relies on the LLM matching specific phrases (e.g., 'focus on') to trigger policy changes (e.g., forbidding character IDs), which may fail if synonyms or variations are used in the scenario text.
  - fix: Perform semantic classification (e.g., framing scale, focus target) in upstream code using structured metadata or a dedicated classifier, and pass the resulting boolean flags or enums to the card builder to drive deterministic policy selection.

- `1494-1663` **P1 / blind_string_mutation**
  - evidence: replace the common-noun person reference inside fixed_elements[i].description... with the matched C## or C##O##
  - why: This establishes a contract for the LLM to perform blind substring replacement on natural-language scenario text (fixed_elements description). This is brittle and prone to errors such as partial replacements or 'phantom' character generation if the LLM fails to identify the exact noun phrase to substitute.
  - fix: Instead of instructing the LLM to perform string replacement, provide the fixed_elements as structured context and ask the LLM to generate the prompt using the provided IDs directly, or use a structured template system where IDs are injected by code.

## `backend/app/modules/pipeline/scene_extractor_v2.py`

- `214-451` **P1 / semantic_string_judgment**
  - evidence: scene_text.find(st), fulltext.find(start_text), if split_text in scene_text
  - why: The pipeline relies on LLMs to 'exactly copy' snippets from the source scenario to identify split points (lines 61, 174, 288). Substring matching is brittle to minor LLM hallucinations in punctuation or spacing, leading to failed or shifted scene boundaries which directly routes the pipeline's structural output.
  - fix: Use character offsets or line indices returned by the LLM, or use a fuzzy matcher/anchor-based approach that is resilient to minor text variations.

- `736-741` **P1 / blind_string_mutation**
  - evidence: _re_cine.sub(r'카메라 구도 선택지:.*?주의:', '주의:', turn_msg, flags=_re_cine.DOTALL)
  - why: The code performs a blind regex replacement on the active prompt text to swap out instructions. This creates a hidden dependency on the exact wording of the prompt template, which will break silently if the template is updated or translated.
  - fix: Use structured prompt templates with named placeholders or conditional blocks instead of regex-based string manipulation over natural language prompt prose.

- `817-823` **P1 / blind_string_mutation**
  - evidence: if marker not in current_t2i and f"[[{char_name}]+[" not in current_t2i: ... var["t2i_prompt"] = current_t2i.rstrip() + " " + suffix
  - why: The code blindly appends character markers to the generated T2I prompt if a specific substring is missing. This can lead to semantic duplication if the LLM described the character using natural language instead of the marker, and it forces a specific visual layout ('visible in the background') regardless of the actual scene context.
  - fix: Instead of post-hoc string appending, provide the required entities as a structured list to the LLM and validate the output, or use a more sophisticated prompt-merging strategy that understands the existing prompt content.

## `prompts/_base/shot_dependency_t2i/7.202605151200/system.md`

- `68` **P1 / semantic_string_judgment**
  - evidence: staging.gaze_target 기반 immobilized mode 산출
  - why: The gaze_target field is being overloaded to carry physical state information (immobilized mode). This is a brittle semantic channel where a field named for one purpose (gaze) is used to infer a completely different physical state for prompt sanitization.
  - fix: Introduce a dedicated physical_state or mobility_status field in the schema instead of inferring state from gaze targets.

- `156-157` **P1 / llm_closed_list_instruction**
  - evidence: human / person / character / body / figure / man / woman / detective / prisoner / child / person silhouette
  - why: This is a closed list of phrases used as a semantic classifier to define what constitutes a 'person' for the purpose of fail-fast validation. It forces the LLM to match open-world descriptions against a brittle list to enforce a non-person constraint on labels.
  - fix: Use a structured entity_type enum (e.g., PERSON, PROP, ENVIRONMENT) and have the LLM categorize entities rather than relying on keyword exclusion in natural language labels.

- `161` **P2 / schema_or_enum_drift**
  - evidence: immobilized_character / character / pose 등 enum 외 값 절대 금지
  - why: The prompt explicitly lists forbidden enum values that likely exist in other parts of the pipeline or previous versions, indicating that the 'kind' field's enum is not centrally enforced or synchronized.
  - fix: Ensure the kind enum is centrally defined in the SOT schema and shared across all pipeline steps to prevent drift.

- `169` **P2 / scenario_dependent_prompt**
  - evidence: the same small reddish mark on the wrist
  - why: This is a highly specific visual detail (a 'reddish mark on the wrist') used as a concrete example. Such specific scenario-dependent props can bias the LLM towards forensic or injury-related scenarios in arbitrary future generations.
  - fix: Replace specific scenario details with generic placeholders like 'a unique texture detail' or 'a specific marking on the object'.
