Skip to content

feat: add pre-flight config validation before pipeline starts - #65

Closed
Grok-King wants to merge 1 commit into
lynote-ai:mainfrom
Grok-King:feat/preflight-config-validation
Closed

Grok-King wants to merge 1 commit into
lynote-ai:mainfrom
Grok-King:feat/preflight-config-validation

Conversation

@Grok-King

Copy link
Copy Markdown

Problem

The pipeline currently validates the LLM API key (via resolve_llm_config) but not the Niutrans key. If niutrans_api_key is empty in config.toml, the pipeline runs Steps 1-3 successfully (consuming LLM tokens and Google Translate quota), then fails at Step 4 with:

RuntimeError: Niutrans error: apikey is invalid

This wastes real money on LLM calls that produced output nobody will see.

Solution

Add _validate_pipeline_config() called at the start of run_standard_pipeline(), before any API calls. It checks:

  1. niutrans_api_key is non-empty — this is the most common miss since it is separate from the LLM provider key
  2. intermediate_lang is a recognized language code — catches typos like intermediate_lang = "finnish" that would silently fail at the Google Translate step

All errors are collected and reported together so the operator can fix everything in one pass.

Before

Step 1: LLM rewrite → success (credits spent)
Step 2: LLM rewrite → success (credits spent)
Step 3: Google Translate → success
Step 4: Niutrans → RuntimeError: apikey is invalid

After

ValueError: Pipeline config validation failed:
  - niutrans_api_key is empty. Set api_keys.niutrans_api_key in config.toml

Fails immediately, before any API calls.

Validate all required API keys and config values before making any
API calls. Prevents wasted LLM credits when a later step would fail
due to missing credentials (e.g. empty niutrans_api_key causes Step 4
auth failure after Steps 1-3 already consumed tokens).

Checks:
- niutrans_api_key is non-empty
- intermediate_lang is a recognized language code

Errors are collected and reported together so the operator can fix
everything at once.
molly554 added a commit that referenced this pull request Sep 16, 2026
Clean reimplementation of the ideas behind #65 and #64:

- _validate_pipeline_config() runs before any API call and reports a missing
  niutrans_api_key or an unrecognized intermediate_lang together, so a
  later-step failure no longer wastes LLM credits (resolves #62)
- --json emits the full result dict (step traces + timing) as JSON with
  ensure_ascii=False; plain and --verbose output unchanged (resolves #60)
- tests/test_pipeline_features.py — 6 cases (validation + CLI)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@molly554

Copy link
Copy Markdown
Contributor

Thanks @Grok-King — the pre-flight validation idea is solid and has landed on main in c3c0fd2 (resolves #62). I reimplemented rather than merging because the submitted raise ValueError(...) put literal newlines inside the string instead of \n, a SyntaxError that stops pipeline.py from importing at all. The shipped version checks the niutrans key and intermediate_lang before any API call, reports all problems together, and has tests. Closing in favor of that commit.

@molly554 molly554 closed this Sep 16, 2026
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