google / google/langextract

Incorrect Extraction Alignment

Open
#151 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
38.6k
Forks
2.7k
Avg merge
3d 15h
Merged PRs (30d)
3

Description

Hello, I've been implementing a custom provider using gemma3:27b which is providing correct looking raw responses but am seeing weird extraction results from the LangExtract library (main branch).

Below is what is returned from my llm api instance
```json
{
"extractions": [
{
"extraction_class": "search_news",
"extraction_text": "articles about Tesla",
"attributes": {
"query": "articles about Tesla"
}
}
]
}
```

DEBUG logs
```
DEBUG:absl:Processing chunk: TextChunk(
interval=[start_index: 0, end_index: 4],
Document ID: doc_8e5527ad,
Chunk Text: 'get articles about Tesla'
)
DEBUG:absl:Top inference result: {
"extractions": [
{
"extraction_class": "search_news",
"extraction_text": "articles about Tesla",
"attributes": {
"query": "articles about Tesla"
}
}
]
}
INFO:absl:Starting resolver process for input text.
DEBUG:absl:Input Text: {
"extractions": [
{
"extraction_class": "search_news",
"extraction_text": "articles about Tesla",
"attributes": {
"query": "articles about Tesla"
}
}
]
}
INFO:absl:Starting string parsing.
DEBUG:absl:input_string: {
"extractions": [
{
"extraction_class": "search_news",
"extraction_text": "articles about Tesla",
"attributes": {
"query": "articles about Tesla"
}
}
]
}
DEBUG:absl:Successfully parsed content.
INFO:absl:Completed parsing of string.
DEBUG:absl:Parsed content: [{'extraction_class': 'search_news', 'extraction_text': 'articles about Tesla', 'attributes': {'query': 'articles about Tesla'}}]
INFO:absl:Starting to extract and order extractions from data.
INFO:absl:Completed extraction and ordering of extractions.
DEBUG:absl:Completed the resolver process.
INFO:absl:Starting alignment process for provided chunk text.
DEBUG:absl:WordAligner: Starting alignment of extractions with the source text. Extraction groups to align: [[Extraction(extraction_class='extraction_class', extraction_text='search_news', char_interval=None, alignment_status=None, extraction_index=1, group_index=0, description=None, attributes=None), Extraction(extraction_class='extraction_text', extraction_text='articles about Tesla', char_interval=None, alignment_status=None, extraction_index=2, group_index=0, description=None, attributes=None), Extraction(extraction_class='attributes', extraction_text="{'query': 'articles about Tesla'}", char_interval=None, alignment_status=None, extraction_index=3, group_index=0, description=None, attributes=None)]]
2025-08-14 12:59:34,302 - langextract.debug - DEBUG - [langextract.tokenizer] CALL: tokenize(text='get articles about Tesla')
2025-08-14 12:59:34,302 - langextract.debug - DEBUG - [langextract.tokenizer] RETURN: tokenize -> TokenizedText...wline=False)]) (0.1 ms)
2025-08-14 12:59:34,303 - langextract.debug - DEBUG - [langextract.tokenizer] CALL: tokenize(text='␟')
2025-08-14 12:59:34,303 - langextract.debug - DEBUG - [langextract.tokenizer] RETURN: tokenize -> TokenizedText...wline=False)]) (0.0 ms)
DEBUG:absl:Using delimiter '␟' for extraction alignment
2025-08-14 12:59:34,303 - langextract.debug - DEBUG - [langextract.tokenizer] CALL: tokenize(text="search_news ␟ articles about Tesla ␟ {'query': 'articles about Tesla'}")
2025-08-14 12:59:34,303 - langextract.debug - DEBUG - [langextract.tokenizer] RETURN: tokenize -> TokenizedText...wline=False)]) (0.1 ms)
DEBUG:absl:Processing extraction group 0 with 3 extractions.
2025-08-14 12:59:34,303 - langextract.debug - DEBUG - [langextract.tokenizer] CALL: tokenize(text='search_news')
2025-08-14 12:59:34,303 - langextract.debug - DEBUG - [langextract.tokenizer] RETURN: tokenize -> TokenizedText...wline=False)]) (0.0 ms)
2025-08-14 12:59:34,303 - langextract.debug - DEBUG - [langextract.tokenizer] CALL: tokenize(text='articles about Tesla')
2025-08-14 12:59:34,303 - langextract.debug - DEBUG - [langextract.tokenizer] RETURN: tokenize -> TokenizedText...wline=False)]) (0.0 ms)
2025-08-14 12:59:34,303 - langextract.debug - DEBUG - [langextract.tokenizer] CALL: tokenize(text="{'query': 'articles about Tesla'}")
2025-08-14 12:59:34,303 - langextract.debug - DEBUG - [langextract.tokenizer] RETURN: tokenize -> TokenizedText...wline=False)]) (0.1 ms)
2025-08-14 12:59:34,303 - langextract.debug - DEBUG - [langextract.tokenizer] CALL: tokenize(text='get articles about Tesla')
2025-08-14 12:59:34,304 - langextract.debug - DEBUG - [langextract.tokenizer] RETURN: tokenize -> TokenizedText...wline=False)]) (0.0 ms)
2025-08-14 12:59:34,304 - langextract.debug - DEBUG - [langextract.tokenizer] CALL: tokenize(text='articles about Tesla')
2025-08-14 12:59:34,304 - langextract.debug - DEBUG - [langextract.tokenizer] RETURN: tokenize -> TokenizedText...wline=False)]) (0.0 ms)
DEBUG:absl:Starting fuzzy alignment for 2 unaligned extractions
2025-08-14 12:59:34,304 - langextract.debug - DEBUG - [langextract.tokenizer] CALL: tokenize(text='search_news')
2025-08-14 12:59:34,304 - langextract.debug - DEBUG - [langextract.tokenizer] RETURN: tokenize -> TokenizedText...wline=False)]) (0.0 ms)
DEBUG:absl:Fuzzy aligning 'search_news' (3 tokens)
2025-08-14 12:59:34,304 - langextract.debug - DEBUG - [langextract.tokenizer] CALL: tokenize(text="{'query': 'articles about Tesla'}")
2025-08-14 12:59:34,304 - langextract.debug - DEBUG - [langextract.tokenizer] RETURN: tokenize -> TokenizedText...wline=False)]) (0.1 ms)
DEBUG:absl:Fuzzy aligning "{'query': 'articles about Tesla'}" (8 tokens)
DEBUG:absl:Final aligned extraction groups: [[Extraction(extraction_class='extraction_class', extraction_text='search_news', char_interval=None, alignment_status=None, extraction_index=1, group_index=0, description=None, attributes=None), Extraction(extraction_class='extraction_text', extraction_text='articles about Tesla', char_interval=CharInterval(start_pos=4, end_pos=24), alignment_status=, extraction_index=2, group_index=0, description=None, attributes=None), Extraction(extraction_class='attributes', extraction_text="{'query': 'articles about Tesla'}", char_interval=None, alignment_status=None, extraction_index=3, group_index=0, description=None, attributes=None)]]
DEBUG:absl:Aligned extractions count: 3
DEBUG:absl:Yielding aligned extraction: Extraction(extraction_class='extraction_class', extraction_text='search_news', char_interval=None, alignment_status=None, extraction_index=1, group_index=0, description=None, attributes=None)
DEBUG:absl:Yielding aligned extraction: Extraction(extraction_class='extraction_text', extraction_text='articles about Tesla', char_interval=CharInterval(start_pos=4, end_pos=24), alignment_status=, extraction_index=2, group_index=0, description=None, attributes=None)
DEBUG:absl:Yielding aligned extraction: Extraction(extraction_class='attributes', extraction_text="{'query': 'articles about Tesla'}", char_interval=None, alignment_status=None, extraction_index=3, group_index=0, description=None, attributes=None)
INFO:absl:Completed alignment process for the provided source_text.
```

However the output printed from result.extractions produces the following
```json
{
"extractions": [
{
"extraction_class": "extraction_class",
"extraction_text": "search_news",
"char_interval": null,
"alignment_status": null,
"extraction_index": 1,
"group_index": 0,
"description": null,
"attributes": null,
"_token_interval": null
},
{
"extraction_class": "extraction_text",
"extraction_text": "articles about Tesla",
"char_interval": {
"start_pos": 4,
"end_pos": 24
},
"alignment_status": "match_exact",
"extraction_index": 2,
"group_index": 0,
"description": null,
"attributes": null,
"_token_interval": {
"start_index": 1,
"end_index": 4
}
},
{
"extraction_class": "attributes",
"extraction_text": "{'query': 'articles about Tesla'}",
"char_interval": null,
"alignment_status": null,
"extraction_index": 3,
"group_index": 0,
"description": null,
"attributes": null,
"_token_interval": null
}
]
}
```

Any thoughts on what could be causing this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.