> ## Documentation Index
> Fetch the complete documentation index at: https://docs.myspellchecker.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Error Types Reference

> mySpellChecker uses a hierarchy of error types for spell checking results and exceptions for system errors.

When something goes wrong, you need to know whether it's a finding in the text being checked (a validation error the user should fix) or a failure in the library itself (a configuration or resource problem you need to fix). These two cases use separate class hierarchies: `Error` subclasses in `Response.errors` for the former, and Python exceptions for the latter.

## Spell Checking Errors

These are returned in `Response.errors` when checking text.

### Error Base Class

All spell checking errors inherit from `Error`:

```python theme={null}
from myspellchecker.core.response import Error

@dataclass
class Error:
    text: str           # The erroneous text
    position: int       # Character position (0-indexed)
    suggestions: List[str]  # Correction suggestions
    error_type: str     # Type identifier
    confidence: float   # 0.0 to 1.0
```

### SyllableError

Invalid syllable detected (Layer 1 validation).

```python theme={null}
from myspellchecker.core.response import SyllableError

error = SyllableError(
    text="မျန်",
    position=0,
    suggestions=["မြန်", "မျန်း"],
    confidence=0.95
)

print(error.error_type)  # "invalid_syllable"
```

**Error Types:**

| Type               | Description                          |
| ------------------ | ------------------------------------ |
| `invalid_syllable` | Standard syllable validation error   |
| `particle_typo`    | Known particle typo (e.g., တယ → တယ်) |
| `medial_confusion` | Ya-pin/Ya-yit confusion              |

### WordError

Invalid word detected (Layer 2 validation).

```python theme={null}
from myspellchecker.core.response import WordError

error = WordError(
    text="မြန်စာ",
    position=0,
    suggestions=["မြန်မာ", "မြန်"],
    syllable_count=2,
    confidence=0.9
)

print(error.error_type)    # "invalid_word"
print(error.syllable_count)  # 2
```

### ContextError

Unlikely word sequence detected (Layer 3 validation).

```python theme={null}
from myspellchecker.core.response import ContextError

error = ContextError(
    text="ဘယ်",
    position=3,
    suggestions=["သွား", "သည်"],
    probability=0.005,
    prev_word="သူ",
    confidence=0.7
)

print(error.error_type)  # "context_probability"
print(error.probability) # 0.005
print(error.prev_word)   # "သူ"
```

**Semantic Error Types:**

| Type               | Source                     | Description                        |
| ------------------ | -------------------------- | ---------------------------------- |
| `semantic_error`   | SemanticStrategy           | AI-detected semantic error via MLM |
| `confusable_error` | ConfusableSemanticStrategy | Valid word, wrong in context       |

Semantic errors use MLM predictions to detect unlikely words. Confusable errors flag words that are valid but confused with a similar-looking alternative.

### GrammarError

Grammar-related errors from grammar checkers.

```python theme={null}
from myspellchecker.core.response import GrammarError

error = GrammarError(
    text="ယေက်",
    position=2,
    suggestions=["ယောက်"],
    error_type="classifier_typo",
    confidence=0.95,
    reason="Classifier typo: ယေက် should be ယောက်"
)

```

**Grammar Error Types:**

| Type                       | Source            | Description                          |
| -------------------------- | ----------------- | ------------------------------------ |
| `aspect_typo`              | AspectChecker     | Verb aspect marker typo              |
| `incomplete_aspect`        | AspectChecker     | Incomplete aspect marking            |
| `invalid_sequence`         | AspectChecker     | Invalid aspect sequence              |
| `typo`                     | ClassifierChecker | Classifier typo (e.g., ယေက် → ယောက်) |
| `agreement`                | ClassifierChecker | Classifier-noun agreement error      |
| `compound_typo`            | CompoundChecker   | Compound word typo                   |
| `incomplete_reduplication` | CompoundChecker   | Incomplete reduplication             |
| `typo`                     | NegationChecker   | Negation pattern typo                |
| `mixed_register`           | RegisterChecker   | Formal/colloquial mixing             |

## Response Object

The complete spell checking result:

```python theme={null}
from myspellchecker.core.response import Response

response = Response(
    text="မျနမ်ာ",           # Original input
    corrected_text="မြန်မာ",  # Auto-corrected
    has_errors=True,          # Quick check flag
    level="syllable",         # Validation level used
    errors=[...],             # List of Error objects
    metadata={                # Processing info
        "processing_time": 0.015,  # seconds
        "syllable_count": 4,
        "word_count": 1
    }
)

# Serialize
print(response.to_json())
print(response.to_dict())
```

## Exceptions

System-level errors for configuration, resources, and processing.

### Exception Hierarchy

<Tree>
  <Tree.Folder name="MyanmarSpellcheckError (base)" defaultOpen>
    <Tree.Folder name="ConfigurationError" defaultOpen>
      <Tree.File name="InvalidConfigError" />
    </Tree.Folder>

    <Tree.Folder name="DataLoadingError" defaultOpen>
      <Tree.File name="MissingDatabaseError" />
    </Tree.Folder>

    <Tree.Folder name="ProcessingError" defaultOpen>
      <Tree.File name="ValidationError" />

      <Tree.File name="TokenizationError" />

      <Tree.File name="NormalizationError" />
    </Tree.Folder>

    <Tree.Folder name="ProviderError" defaultOpen>
      <Tree.File name="ConnectionPoolError" />
    </Tree.Folder>

    <Tree.Folder name="PipelineError" defaultOpen>
      <Tree.File name="IngestionError" />

      <Tree.File name="PackagingError" />
    </Tree.Folder>

    <Tree.Folder name="ModelError" defaultOpen>
      <Tree.File name="ModelLoadError" />

      <Tree.File name="InferenceError" />
    </Tree.Folder>

    <Tree.File name="MissingDependencyError" />

    <Tree.File name="InsufficientStorageError" />

    <Tree.File name="CacheError" />
  </Tree.Folder>
</Tree>

### Common Exceptions

#### MyanmarSpellcheckError

Base exception for all library errors:

```python theme={null}
from myspellchecker.core.exceptions import MyanmarSpellcheckError

try:
    checker.check(text)
except MyanmarSpellcheckError as e:
    print(f"Spell check error: {e}")
```

#### MissingDatabaseError

Database not found:

```python theme={null}
from myspellchecker.core.exceptions import MissingDatabaseError

try:
    checker = SpellChecker()
except MissingDatabaseError as e:
    print(f"Database not found: {e}")
    print(f"Searched: {e.searched_paths}")
    print(f"Solution: {e.suggestion}")
```

#### MissingDependencyError

Optional dependency not installed:

```python theme={null}
from myspellchecker.core.exceptions import MissingDependencyError

try:
    from myspellchecker.algorithms import TransformerPOSTagger
except MissingDependencyError as e:
    print(f"Missing dependency: {e}")
    # Install: pip install myspellchecker[transformers]
```

#### ConfigurationError

Invalid configuration:

```python theme={null}
from myspellchecker.core.exceptions import ConfigurationError, InvalidConfigError

try:
    config = SpellCheckerConfig(max_edit_distance=10)  # Invalid
except InvalidConfigError as e:
    print(f"Invalid config: {e}")
```

#### ProcessingError

Text processing failure:

```python theme={null}
from myspellchecker.core.exceptions import (
    ProcessingError,
    ValidationError,
    TokenizationError,
    NormalizationError
)

try:
    result = checker.check(text)
except ValidationError as e:
    print(f"Invalid text: {e}")
except TokenizationError as e:
    print(f"Segmentation failed: {e}")
except NormalizationError as e:
    print(f"Normalization failed: {e}")
except ProcessingError as e:
    print(f"Processing failed: {e}")
```

#### ProviderError

Database provider failure:

```python theme={null}
from myspellchecker.core.exceptions import ProviderError, ConnectionPoolError

try:
    result = checker.check(text)
except ConnectionPoolError as e:
    print(f"Connection pool exhausted: {e}")
except ProviderError as e:
    print(f"Provider error: {e}")
```

#### PipelineError

Data pipeline failure:

```python theme={null}
from myspellchecker.core.exceptions import PipelineError, IngestionError, PackagingError

try:
    pipeline.run()
except IngestionError as e:
    print(f"Ingestion failed: {e}")
    print(f"Missing files: {e.missing_files}")
    print(f"Failed files: {e.failed_files}")
except PackagingError as e:
    print(f"Packaging failed: {e}")
except PipelineError as e:
    print(f"Pipeline error: {e}")
```

#### ModelError

ML model failure:

```python theme={null}
from myspellchecker.core.exceptions import ModelError, ModelLoadError, InferenceError

try:
    tagger.tag(text)
except ModelLoadError as e:
    print(f"Model load failed: {e}")
except InferenceError as e:
    print(f"Inference failed: {e}")
except ModelError as e:
    print(f"Model error: {e}")
```

### Grouping Exceptions

You can create your own exception tuples for consistent error handling:

```python theme={null}
from myspellchecker.core.exceptions import (
    DataLoadingError,
    MissingDatabaseError,
    ProviderError,
    ProcessingError,
    ValidationError,
)

# Group related exceptions for try/except
DATABASE_EXCEPTIONS = (DataLoadingError, MissingDatabaseError, ProviderError)
PROCESSING_EXCEPTIONS = (ProcessingError, ValidationError)

try:
    result = process_text(text)
except PROCESSING_EXCEPTIONS as e:
    logger.error(f"Processing failed: {e}")
```

## Error Type Constants

```python theme={null}
from myspellchecker.core.constants import ErrorType

# --- Core validation errors ---
ErrorType.SYLLABLE                  # "invalid_syllable"
ErrorType.WORD                      # "invalid_word"
ErrorType.CONTEXT_PROBABILITY       # "context_probability"
ErrorType.GRAMMAR                   # "grammar_error"

# --- Syllable-level specific errors ---
ErrorType.PARTICLE_TYPO             # "particle_typo"
ErrorType.MEDIAL_CONFUSION          # "medial_confusion"

# --- Colloquial variant errors ---
ErrorType.COLLOQUIAL_VARIANT        # "colloquial_variant"  (strict mode)
ErrorType.COLLOQUIAL_INFO           # "colloquial_info"     (lenient mode)

# --- Validation strategy errors ---
ErrorType.QUESTION_STRUCTURE        # "question_structure"
ErrorType.SYNTAX_ERROR              # "syntax_error"
ErrorType.HOMOPHONE_ERROR           # "homophone_error"
ErrorType.TONE_AMBIGUITY            # "tone_ambiguity"
ErrorType.POS_SEQUENCE_ERROR        # "pos_sequence_error"
ErrorType.SEMANTIC_ERROR            # "semantic_error"

# --- Encoding errors ---
ErrorType.ZAWGYI_ENCODING           # "zawgyi_encoding"

# --- Grammar checker specific errors ---
ErrorType.MIXED_REGISTER            # "mixed_register"
ErrorType.ASPECT_TYPO               # "aspect_typo"
ErrorType.INVALID_SEQUENCE          # "invalid_sequence"
ErrorType.INCOMPLETE_ASPECT         # "incomplete_aspect"
ErrorType.TYPO                      # "typo"
ErrorType.AGREEMENT                 # "agreement"
ErrorType.COMPOUND_TYPO             # "compound_typo"
ErrorType.INCOMPLETE_REDUPLICATION  # "incomplete_reduplication"
ErrorType.CLASSIFIER_TYPO           # "classifier_typo"

# --- Text-level detector errors (spellchecker.py) ---
ErrorType.COLLOQUIAL_CONTRACTION    # "colloquial_contraction"
ErrorType.PARTICLE_CONFUSION        # "particle_confusion"
ErrorType.HA_HTOE_CONFUSION         # "ha_htoe_confusion"
ErrorType.DANGLING_PARTICLE         # "dangling_particle"
ErrorType.DANGLING_WORD             # "dangling_word"
ErrorType.MISSING_CONJUNCTION       # "missing_conjunction"
ErrorType.TENSE_MISMATCH            # "tense_mismatch"
ErrorType.REGISTER_MIXING           # "register_mixing"

# --- Grammar checker class-level errors ---
ErrorType.NEGATION_ERROR            # "negation_error"
ErrorType.REGISTER_ERROR            # "register_error"
ErrorType.MERGED_WORD               # "merged_word"
ErrorType.ASPECT_ERROR              # "aspect_error"
ErrorType.CLASSIFIER_ERROR          # "classifier_error"
ErrorType.COMPOUND_ERROR            # "compound_error"

# --- Orthography errors ---
ErrorType.MEDIAL_ORDER_ERROR        # "medial_order_error"
ErrorType.MEDIAL_COMPATIBILITY_ERROR  # "medial_compatibility_error"
ErrorType.VOWEL_AFTER_ASAT          # "vowel_after_asat"
ErrorType.BROKEN_VIRAMA             # "broken_virama"
ErrorType.CONFUSABLE_ERROR          # "confusable_error"
ErrorType.BROKEN_STACKING           # "broken_stacking"
ErrorType.BROKEN_COMPOUND           # "broken_compound"
ErrorType.LEADING_VOWEL_E           # "leading_vowel_e"
ErrorType.INCOMPLETE_STACKING       # "incomplete_stacking"

# --- Syntactic/semantic errors ---
ErrorType.NEGATION_SFP_MISMATCH     # "negation_sfp_mismatch"
ErrorType.MERGED_SFP_CONJUNCTION    # "merged_sfp_conjunction"
ErrorType.ASPECT_ADVERB_CONFLICT    # "aspect_adverb_conflict"

# --- Punctuation errors ---
ErrorType.DUPLICATE_PUNCTUATION     # "duplicate_punctuation"
ErrorType.WRONG_PUNCTUATION         # "wrong_punctuation"
ErrorType.MISSING_PUNCTUATION       # "missing_punctuation"

# --- Additional detection errors ---
ErrorType.MISSING_ASAT              # "missing_asat"
ErrorType.PARTICLE_MISUSE           # "particle_misuse"
ErrorType.COLLOCATION_ERROR         # "collocation_error"
```

## Best Practices

### 1. Catch Specific Exceptions

```python theme={null}
try:
    result = checker.check(text)
except MissingDatabaseError:
    # Handle missing database specifically
    build_sample_database()
except MyanmarSpellcheckError:
    # Handle other library errors
    log_error()
```

### 2. Check Error Types

```python theme={null}
for error in result.errors:
    if error.error_type == "invalid_syllable":
        # Handle syllable error
        pass
    elif error.error_type.startswith("classifier"):
        # Handle classifier errors
        pass
```

### 3. Use Confidence Scores

```python theme={null}
HIGH_CONFIDENCE = 0.8

for error in result.errors:
    if error.confidence >= HIGH_CONFIDENCE:
        # Auto-correct high confidence errors
        apply_correction(error)
    else:
        # Show suggestions for low confidence
        show_suggestions(error)
```

## Common Myanmar Spelling Errors

### Error Frequency by Category

Based on corpus analysis:

| Error Type           | Frequency | Detection Layer | Example                                       |
| -------------------- | --------- | --------------- | --------------------------------------------- |
| Medial ြ/ျ confusion | 35%       | Syllable        | ကြောင်/ကျောင်                                 |
| Missing asat         | 20%       | Syllable        | အိမ/အိမ်                                      |
| Vowel length         | 15%       | Syllable/Word   | သု/သူ                                         |
| Particle errors      | 12%       | Grammar         | မှာ/မှ                                        |
| Context (real-word)  | 10%       | Context         | ထမင်းသွား/ထမင်းစား                            |
| Stacking errors      | 5%        | Syllable        | သမတ ("broken stacking") → သမ္မတ ("president") |
| Other                | 3%        | Various         | -                                             |

### Detection by Validation Layer

**Layer 1 - Syllable Validation:**

```python theme={null}
result = checker.check("ကွြ")   # Invalid medial order → Suggestion: ကြွ
result = checker.check("ကိီ")   # Incompatible vowels
```

**Layer 2 - Word Validation:**

```python theme={null}
result = checker.check("မယ်နမာ")  # Unknown word → Suggestions: ["မြန်မာ", ...]
```

**Layer 2.5 - Grammar Checking:**

```python theme={null}
result = checker.check("သွားကို")  # Verb with object particle → GrammarError
```

**Layer 3 - Context Validation:**

```python theme={null}
result = checker.check("ထမင်းသွား")  # Low probability bigram → Suggestion: ထမင်းစား
```

### Medial-Consonant Compatibility

Not all medials are compatible with all consonants:

| Medial      | Compatible With           | Incompatible With     |
| ----------- | ------------------------- | --------------------- |
| Ha-htoe (ှ) | Sonorants (န, မ, လ, etc.) | Stops (က, ခ, ဂ, etc.) |
| Ya-yit (ြ)  | Ka-group, Pa-group        | Tha (သ)               |

### Stacking Errors

```yaml theme={null}
Correct: မင်္ဂလာ (blessing)     |  Error: မင်ဂလာ (missing stack)
Correct: ဗုဒ္ဓ (Buddha)          |  Error: ဗုဒ (incomplete)
```

## See Also

* [Response API](/core/spellchecker) - SpellChecker API reference
* [Grammar Checkers](/features/grammar-checkers) - Grammar error details
* [Configuration](/guides/configuration) - Error handling configuration
