AnswerDotAI / AnswerDotAI/llms-txt

Error when `llms.txt` contains level-2 sections and no links

Open
#16 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
2.6k
Forks
163
Avg merge
1m
Merged PRs (30d)
1

Description

If the `llms.txt` document contains a level-2 section, `parse_link()` throws if there aren't any links in the document. Here's an example using a variation of a test case:

```bash
cat << 'EOF' > llms.txt
# No Links Title

## Description

> No description

Some details without links
EOF

llms_txt2ctx llms.txt
```

```bash
Traceback (most recent call last):
File "/Users/garrick/work/external/AnswerDotAI/llms-txt/.venv/bin/llms_txt2ctx", line 8, in
sys.exit(llms_txt2ctx())
~~~~~~~~~~~~^^
File "/Users/garrick/work/external/AnswerDotAI/llms-txt/.venv/lib/python3.13/site-packages/fastcore/script.py", line 121, in _f
return tfunc(**merge(args, args_from_prog(func, xtra)))
File "/Users/garrick/work/external/AnswerDotAI/llms-txt/llms_txt/core.py", line 125, in llms_txt2ctx
ctx = create_ctx(Path(fname).read_text(), optional=optional, n_workers=n_workers)
File "/Users/garrick/work/external/AnswerDotAI/llms-txt/llms_txt/core.py", line 112, in create_ctx
d = parse_llms_file(txt)
File "/Users/garrick/work/external/AnswerDotAI/llms-txt/llms_txt/core.py", line 57, in parse_llms_file
start,sects = _parse_llms(txt)
~~~~~~~~~~~^^^^^
File "/Users/garrick/work/external/AnswerDotAI/llms-txt/llms_txt/core.py", line 51, in _parse_llms
sects = {k: _parse_links(v) for k,v in d.items()}
~~~~~~~~~~~~^^^
File "/Users/garrick/work/external/AnswerDotAI/llms-txt/llms_txt/core.py", line 45, in _parse_links
return [parse_link(l) for l in re.split(r'\n+', links.strip()) if l.strip()]
~~~~~~~~~~^^^
File "/Users/garrick/work/external/AnswerDotAI/llms-txt/llms_txt/core.py", line 41, in parse_link
return re.search(pat, txt).groupdict()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'groupdict'
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with llms_txt/core.py, especially parse_link() and _parse_links(), then run the llms_txt2ctx example from the issue with an llms.txt file containing a level-2 section but no links. Done means that input is parsed without the AttributeError and the command completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.