All MicroEvals
1. detect_language(text, allowed=()) throws a runtime IndexE...
Create MicroEval
Header image for 1. detect_language(text, allowed=()) throws a runtime IndexE...

1. detect_language(text, allowed=()) throws a runtime IndexE...

Prompt

1. detect_language(text, allowed=()) throws a runtime IndexError: tuple index out of range when the allowed tuple is empty, at the line return allowed[0]. 2. detect_language() gives double points for the words "miert" / "miĂ©rt": the HU_FUNCTION_WORDS contains both forms, but both fold() forms become "miert", so in case of a single occurrence, sum() counts it twice (6.0 points) instead of 3.0. 3. In extract_features() entity extraction, the match.start() > 0 filter condition drops all real proper nouns that start at the very first character (index 0) of the text. 4. In extract_features() entity extraction, the match.start() > 0 filter does not filter out later sentence-beginning, non-entity capitalized words from texts consisting of multiple sentences, since their index is greater than 0. 5. In extract_features() entity filtering, the len(match.group(0)) > 2 condition is redundant dead code, because the _ENTITY_RE pattern (\p{Lu}\p{L}{2,}) already exclusively returns matches of at least 3 characters in length. 6. _hits() and _any_hit() perform substring searching without word boundaries (fold(phrase) in folded), which causes massive false positives when a phrase appears inside another word (e.g., "source" in "resource", "link" in "blink", "cite" in "excited", "proof" in "waterproof", "provide" in "provider"). 7. RECENCY_MARKERS["hu"] contains the word "ma", which due to substring searching without word boundaries almost always erroneously activates recency_marker=True for Hungarian texts (matching in "magyar", "tanulmĂĄny", "folyamat", "marad", "majd", "forma"). 8. RECENCY_MARKERS["hu"] contains the word "most", which erroneously matches as a substring in Hungarian words ("mostani", "kimostam") and English words ("almost", "mostly"). 9. RECENCY_MARKERS["hu"] contains the word "iden", which erroneously matches as a substring in "identitĂĄs", "resident", "president". 10. WH_FACT_PATTERNS["hu"] contains short, unbounded substrings ("ki a", "ki az", "ki volt", "hany"), which erroneously match common words ("aki a", "valaki az", "senki volt", "nĂ©hĂĄny", "hanyag"). 11. MECHANISM_FRAMES["hu"] contains the word "mitol", which erroneously matches as a substring in the word "mitolĂłgia". 12. The source_demand_hits hit list artificially multiplies the hits because base words and their inflected/plural forms are present simultaneously in the dictionary (e.g., for the word "sources", both "source" and "sources" are added; for the word "documents", both "document" and "documents" are added; for the word "forrasokat", both "forras", "forrasok" and "forrasokat" are added). 13. Multi-word phrases in _hits() and _any_hit() fail when punctuation or non-standard whitespace is placed between the words (e.g., the correctly spelled "tudott dolog, de" does not match the dictionary entry "tudott dolog de" due to the comma). 14. fold() does not apply Unicode decomposition normalization (NFC/NFKD), so decomposed NFD characters (e.g., e\u0301) are not converted to their ASCII equivalents, failing dictionary matches and language recognition. 15. _FOLD_MAP contains redundant uppercase mappings ("Á": "a", "É": "e", etc.), which are inaccessible dead data because fold() calls the .translate() method before calling text.casefold(). 16. _WORD_RE handles only the ASCII apostrophe (') and not the typographic/curly apostrophe (', U+2019), thus splitting contractions and names (don't, it's) into two truncated words (don, t). 17. _WORD_RE can only start with a letter (\p{L}), thus ignoring numbers, which causes token_count to be 0 for purely numeric input, despite RECENCY_MARKERS explicitly containing year numbers. 18. _WORD_RE allows trailing hyphen and apostrophe ([\p{L}\p{M}\-']*), thus creating tokens (e.g., "word-", "word'") that fail in dictionaries checking for exact matches. 19. _hits() and _any_hit() unnecessarily rerun the fold(phrase) call on every function invocation for all static elements of the dictionaries instead of using pre-mapped constants. 20. detect_language() performs redundant double lowercasing: first lowered = text.casefold() runs, then fold(token) called on the tokens runs .casefold() again. 21. _imperative_hits() transforms all tokens of the input with the fold() function ([fold(token) for token in tokens]), when only the first four tokens (tokens[:4]) are needed. 22. _imperative_hits() runs the fold(verb) call on each element of the verb lists on every invocation instead of using a pre-mapped verb set. 23. extract_features() first generates all entity matches in memory, then truncates them to the first 12 elements ([:12]), which causes unnecessary memory load on long texts. 24. named_entity_candidates does not contain deduplication, so repeatedly occurring identical early entities fill the 12-element frame, displacing later unique entities. 25. FIRST_PERSON_EXPERIENTIAL["hu"] contains three elements ("a fonokom", "a fonoköm", "a fonököm") which all become the completely identical string "a fonokom" after fold(), performing unnecessary duplicate checks. 26. FIRST_PERSON_EXPERIENTIAL["hu"] contains the incorrectly spelled literal "atĂ©ltem" (mixed accented form; correctly "ĂĄtĂ©ltem" or unaccented "ateltem"). 27. RECENCY_MARKERS contains statically hardcoded years ("2024", "2025", "2026"), which become outdated over time, and without numeric word boundaries, they erroneously activate the recency_marker flag for arbitrary identifiers, phone numbers, or codes. 28. extract_features() silently falls back to "en" language without error message or warning when receiving a non-normalized BCP-47 language code (e.g., "hu-HU"), a value with whitespace ("hu "), or an unsupported language. 29. extract_features() unconditionally marks every text containing a ? character as "direct_question" type for question-type classification, disregarding the request mood (e.g., relabeling the request "Can you provide sources?" as a question), and also erroneously activates on question marks in URLs or quotation marks. 30. The logical value of WH_FACT_PATTERNS is calculated, but the code does not use it for determining interrogative_type, thus classifying WH-questions without a question mark (e.g., "Who is the director") as "statement". 31. _imperative_hits() converts the elements of folded_tokens[:4] into a set (set), losing word order and syntactic position, thus activating request_mood=True for declarative sentences where the verb is not in imperative mood but appears in the first 4 words (e.g., "They confirm the data", "The list gives details"). 32. _ENTITY_RE requires the \p{Lu}\p{L}{2,} pattern for every syllable, thus it cannot recognize valid 2-letter proper nouns, acronyms, and initials (e.g., "EU", "US", "AI", "Xi"). 33. _ENTITY_RE does not allow hyphen, apostrophe, numbers, or lowercase name components, thus truncating or splitting compound proper nouns (e.g., "O'Connor", "Coca-Cola", "GPT-4", "University of Oxford"). 34. _ENTITY_RE uses the \s+ pattern between capitalized words without checking sentence boundaries, thus erroneously combining capitalized words spanning line breaks or different sentences into a single continuous entity. 35. extract_features() language validation exclusively checks the lang not in SOURCE_DEMAND_LEXICON condition; if in the future any other dictionary does not contain the given language key, the code crashes with a runtime KeyError exception. from __future__ import annotations import json from adp.config import AppConfig from adp.providers.base import LLMProvider, ProviderError from adp.schemas import Classification, LLMClassification, Message, QueryCategory, QueryFeatures SYSTEM_PROMPT = ( "You are a deterministic query classifier inside a response pipeline. " "You never answer the user's question. You only assign exactly one category label. " "Categories and their definitions:\n" "EVIDENTIARY_REQUEST: the user explicitly demands sources, proof, documents, citations " "or official confirmation.\n" "FACTUAL_LOOKUP: the user asks for a discrete current fact (name, date, number, price, " "statute) that changes over time.\n" "INTERPRETATION: the user states a premise or observation and wants it interpreted.\n" "MECHANISM: the user asks why or how something works, what drives or causes it.\n" "SCENARIO_ANALYSIS: the situation is underdetermined; several explanations compete.\n" "OPEN_SECRET: the topic is socially known but has no official admission.\n" "PERSONAL_NARRATIVE: the user recounts their own experience, memory or observation.\n" "Return only a JSON object with keys 'category', 'confidence' (0..1) and 'rationale'." ) USER_TEMPLATE = ( "User turn (language={language}):\n" "---\n{text}\n---\n" "Deterministic feature extraction:\n{features}\n" "Assign exactly one category." ) class LlmClassifier: def __init__(self, provider: LLMProvider, config: AppConfig) -> None: self._provider = provider self._config = config def classify(self, text: str, features: QueryFeatures) -> Classification: payload = features.model_dump() messages = [ Message(role="system", content=SYSTEM_PROMPT), Message( role="user", content=USER_TEMPLATE.format( language=features.language, text=text.strip(), features=json.dumps(payload, ensure_ascii=False, indent=2), ), ), ] try: result = self._provider.generate_structured(messages, 0.0, LLMClassification) except ProviderError as exc: return Classification( category=QueryCategory.SCENARIO_ANALYSIS, confidence=0.4, source="llm:unavailable", rationale=f"structured classification unavailable ({exc}); defaulted to scenario", features=features, underdetermined=True, ) if result.confidence < self._config.thresholds.classifier_confidence_min: return Classification( category=QueryCategory.SCENARIO_ANALYSIS, confidence=result.confidence, source="llm:low_confidence", rationale=( f"model proposed {result.category} with confidence {result.confidence:.2f} " "below threshold; defaulted to scenario analysis" ), features=features, underdetermined=True, ) underdetermined = result.category in { QueryCategory.SCENARIO_ANALYSIS, QueryCategory.INTERPRETATION, } return Classification( category=result.category, confidence=result.confidence, source="llm", rationale=result.rationale or "structured model classification", features=features, underdetermined=underdetermined, ) Send back the complete code with all the fixes. Fix each of the listed errors one by one, making sure to actually correct them so that there are 0 errors remaining. Keep the original imports, since the files exist. Write out every single character; do not abbreviate anything. Fix every error. There must be exactly one file. Do not write anything else; just output the complete code, and it must not contain any comments. Never, under any circumstances, use simplified, substitute, dummy, simulated, or fake code. Write the entire file as complete, unabridged, production-ready code in a single code block. It must be 100% error-free, a complete, error-free file, and must be submitted as a downloadable file. These requirements are mandatory and must be strictly adhered to. If no list of errors is provided, you must find all the errors and fix them. If there were comments in the original code, delete them. And most importantly: YOU MUST NEVER SIMPLIFY!

Drag to resize
Drag to resize