Skip to content

feat: smart save_to with full path support and bug fix#85

Open
mikesoennichsen wants to merge 6 commits intomainfrom
feat/smart-save-to
Open

feat: smart save_to with full path support and bug fix#85
mikesoennichsen wants to merge 6 commits intomainfrom
feat/smart-save-to

Conversation

@mikesoennichsen
Copy link
Copy Markdown
Contributor

@mikesoennichsen mikesoennichsen commented Apr 9, 2026

Summary

Three changes to the save_to parameter:

  1. Bug fix: When markdown is a raw string (e.g. chaining parse()extract()), the
    output filename is now output_extract_output.json instead of garbage derived from the
    markdown content. All string inputs are treated as content, not file paths — file inputs
    should use Path objects, tuples, or IO objects.

  2. Full path support: save_to now accepts a full file path ending in .json in addition
    to a directory. Directory mode auto-generates the filename as before.

    # Directory mode (existing behavior)
    client.extract(markdown=Path("doc.pdf"), save_to="./output")
    # → ./output/doc_extract_output.json
    
    # Full path mode (new)
    client.extract(markdown=result.markdown, save_to="./output/my_result.json")
    # → ./output/my_result.json
  3. Async support: Added save_to to AsyncLandingAIADE.extract(), .parse(), and .split().

Test plan

  • 28 unit tests passing (filename extraction, full-path mode, async methods)
  • ruff check clean
  • Manual: chain parse()extract() with both save_to modes

🤖 Generated with Claude Code

mikesoennichsen and others added 3 commits April 9, 2026 12:54
Previously, passing a raw markdown string to extract() or split() would
treat the markdown content as a file path via Path(str).stem, producing
garbage filenames. Now strings are only treated as file paths if they
have a file extension.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
save_to now accepts either a directory path (auto-generates filename as
{input_file}_{method}_output.json) or a full file path ending in .json
(saves to that exact path). Parent directories are created automatically.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add save_to parameter to AsyncLandingAIADE.extract(), parse(), and
split() methods, mirroring the sync client behavior. Supports both
directory mode and full .json file path mode.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 9, 2026 20:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances response saving ergonomics by allowing save_to to accept either an output directory (existing behavior) or an explicit .json file path (new behavior), and extends save_to support to async client methods. It also adjusts filename inference to avoid treating raw markdown strings as file paths.

Changes:

  • Update _save_response to support save_to as either a directory or a full .json output path.
  • Refine _get_input_filename behavior for str inputs to reduce accidental filename derivation from raw markdown.
  • Add save_to support to async extract, parse, and split, plus expanded test coverage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/landingai_ade/_client.py Implements full-path .json save support, updates filename inference, and adds async save_to handling.
tests/test_save_to.py Adds tests for raw-markdown filename inference, full-path save behavior, and async save_to support.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Strings passed as file_input are always raw content (markdown), not file
paths. The SDK sends strings to the API as content, not as file uploads.
File inputs should use Path objects, tuples, or IO objects. This removes
the unreliable Path(s).suffix heuristic that could misclassify strings
containing periods (e.g. "example.com", "$10.50") as file paths.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mikesoennichsen mikesoennichsen changed the title feat: smart save_to with full path support and markdown bug fix feat: smart save_to with full path support and bug fix Apr 9, 2026
When no input filename can be derived (e.g. raw markdown string), the
auto-generated name is now {method}_output.json instead of the redundant
output_{method}_output.json.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 10, 2026 01:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Update save_to docstrings on all 6 methods to describe the fallback
  naming when no input filename is available
- Update _save_response docstring to mention the "output" special case
- Handle os.PathLike inputs (not just Path) in _get_input_filename

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants