Error while parsing the file 'file_path': 'markdown' #185

Closed
opened 2026-02-16 00:17:04 -05:00 by yindo · 0 comments
Owner

Originally created by @tferracina on GitHub (Jul 13, 2024).

The first time the parser was ran on the file did not throw any errors. But while experimenting with different parsing instructions I've had to parse the same file multiple times and every consequent parse threw this error, even changing the result_type to 'text' did not help.

The following is the code:

from llama_parse import LlamaParse
from prompts_doc_parser import parser_instructions_invoice
    
def parse_pdf(file_path, parser):
    logger.info(f'Parsing file: {file_path}')
    try:
        parsed_documents = parser.load_data(file_path)
        if parsed_documents and len(parsed_documents) > 0:
            # Assuming the first document contains the parsed content
            return parsed_documents[0].text
        else:
            logger.warning(f"No content parsed from {file_path}")
            return None
    except Exception as e:
        logger.error(f"Error parsing file {file_path}: {str(e)}")
        return None

def main():
    os.makedirs(OUTPUT_DIR, exist_ok=True)

    # Initialize LlamaParse
    parser = LlamaParse(
        api_key=LLAMA_CLOUD_API_KEY,
        result_type="text",
        custom_instructions=parser_instructions_invoice(),
        gpt4o_mode=True,
        gpt4o_api_key=OPENAI_API_KEY  # Use this if you want to use GPT-4
    )

    # Process all PDF files in the data directory
    for filename in os.listdir(DATA_DIR):
        if filename.endswith('.pdf'):
            file_path = os.path.join(DATA_DIR, filename)
            #output_file = os.path.join(OUTPUT_DIR, f"{filename[:-4]}_parsed.txt")
            output_file = os.path.join(OUTPUT_DIR, f"{filename[:-4]} instruct2.txt")

            # Check if the parsed file already exists
            if os.path.exists(output_file):
                logger.info(f"Parsed file already exists for {filename}, skipping.")
                continue

            parsed_content = parse_pdf(file_path, parser)
            
            if parsed_content:
                # Save parsed content to a text file
                with open(output_file, 'w', encoding='utf-8') as f:
                    f.write(parsed_content)
                logger.info(f"Parsed content saved to {output_file}")
            else:
                logger.warning(f"Failed to parse {filename}")

    logger.info("All documents processed.")```
    
Error:
INFO:__main__:Parsing file: ./data/test/invoices.pdf
INFO:httpx:HTTP Request: POST https://api.cloud.llamaindex.ai/api/parsing/upload "HTTP/1.1 200 OK"
Started parsing the file under job_id 45137e57-414c-49ac-a8a7-9342a9da334f
INFO:httpx:HTTP Request: GET https://api.cloud.llamaindex.ai/api/parsing/job/45137e57-414c-49ac-a8a7-9342a9da334f "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://api.cloud.llamaindex.ai/api/parsing/job/45137e57-414c-49ac-a8a7-9342a9da334f "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: GET https://api.cloud.llamaindex.ai/api/parsing/job/45137e57-414c-49ac-a8a7-9342a9da334f/result/text "HTTP/1.1 404 Not Found"
Error while parsing the file './data/test/invoices.pdf': 'markdown'
WARNING:__main__:No content parsed from ./data/test/invoices.pdf
WARNING:__main__:Failed to parse invoices.pdf
Originally created by @tferracina on GitHub (Jul 13, 2024). The first time the parser was ran on the file did not throw any errors. But while experimenting with different parsing instructions I've had to parse the same file multiple times and every consequent parse threw this error, even changing the result_type to 'text' did not help. The following is the code: ``` from llama_parse import LlamaParse from prompts_doc_parser import parser_instructions_invoice def parse_pdf(file_path, parser): logger.info(f'Parsing file: {file_path}') try: parsed_documents = parser.load_data(file_path) if parsed_documents and len(parsed_documents) > 0: # Assuming the first document contains the parsed content return parsed_documents[0].text else: logger.warning(f"No content parsed from {file_path}") return None except Exception as e: logger.error(f"Error parsing file {file_path}: {str(e)}") return None def main(): os.makedirs(OUTPUT_DIR, exist_ok=True) # Initialize LlamaParse parser = LlamaParse( api_key=LLAMA_CLOUD_API_KEY, result_type="text", custom_instructions=parser_instructions_invoice(), gpt4o_mode=True, gpt4o_api_key=OPENAI_API_KEY # Use this if you want to use GPT-4 ) # Process all PDF files in the data directory for filename in os.listdir(DATA_DIR): if filename.endswith('.pdf'): file_path = os.path.join(DATA_DIR, filename) #output_file = os.path.join(OUTPUT_DIR, f"{filename[:-4]}_parsed.txt") output_file = os.path.join(OUTPUT_DIR, f"{filename[:-4]} instruct2.txt") # Check if the parsed file already exists if os.path.exists(output_file): logger.info(f"Parsed file already exists for {filename}, skipping.") continue parsed_content = parse_pdf(file_path, parser) if parsed_content: # Save parsed content to a text file with open(output_file, 'w', encoding='utf-8') as f: f.write(parsed_content) logger.info(f"Parsed content saved to {output_file}") else: logger.warning(f"Failed to parse {filename}") logger.info("All documents processed.")``` Error: INFO:__main__:Parsing file: ./data/test/invoices.pdf INFO:httpx:HTTP Request: POST https://api.cloud.llamaindex.ai/api/parsing/upload "HTTP/1.1 200 OK" Started parsing the file under job_id 45137e57-414c-49ac-a8a7-9342a9da334f INFO:httpx:HTTP Request: GET https://api.cloud.llamaindex.ai/api/parsing/job/45137e57-414c-49ac-a8a7-9342a9da334f "HTTP/1.1 200 OK" INFO:httpx:HTTP Request: GET https://api.cloud.llamaindex.ai/api/parsing/job/45137e57-414c-49ac-a8a7-9342a9da334f "HTTP/1.1 200 OK" INFO:httpx:HTTP Request: GET https://api.cloud.llamaindex.ai/api/parsing/job/45137e57-414c-49ac-a8a7-9342a9da334f/result/text "HTTP/1.1 404 Not Found" Error while parsing the file './data/test/invoices.pdf': 'markdown' WARNING:__main__:No content parsed from ./data/test/invoices.pdf WARNING:__main__:Failed to parse invoices.pdf
yindo closed this issue 2026-02-16 00:17:04 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: run-llama/llama_cloud_services#185