Repository navigation
feat: parser component param check and family mapping fixes - #17312
Conversation
📝 WalkthroughWalkthroughParser construction now validates PDF and image setups, media dispatch recognizes additional file types, and audio defaults use JSON output. No-CGO PDF and office parser methods now accept context values, with tests updated for the new signatures. ChangesParser configuration and dispatch
No-CGO parser context propagation
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
internal/ingestion/component/parser.go (1)
133-176: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Check()is bypassed whenparams == nil.The pre-existing early return at Lines 136-138 short-circuits before the new
pc.Check()call at Lines 172-174, soNewParserComponent(nil)never validates the shipped defaults. It's harmless today only becausedefaultSetups()/schema.ParserParam{}.Defaults()happen to be valid, but it silently defeats the doc comment's promise that validation "runs at construction time," andTestParserComponent_New_RunsCheck'sNewParserComponent(nil)case gives false confidence — it isn't actually exercisingCheck()against the defaults it claims to validate.🛡️ Proposed fix — always run Check(), even for nil params
func NewParserComponent(params map[string]any) (runtime.Component, error) { p := schema.ParserParam{}.Defaults() s := defaultSetups() - if params == nil { - return &ParserComponent{Setups: s, Param: p}, nil - } - for k, raw := range params { - if k == "outputs" { - continue - } - ftCfg, ok := raw.(map[string]any) - if !ok { - continue - } - if _, exists := s[k]; !exists { - s[k] = schema.ParserSetup{} - } - for fk, fv := range ftCfg { - s[k][fk] = fv - } - } - if rawAllowed, ok := params["allowed_output_format"].(map[string]any); ok { - ... + if params != nil { + for k, raw := range params { + if k == "outputs" { + continue + } + ftCfg, ok := raw.(map[string]any) + if !ok { + continue + } + if _, exists := s[k]; !exists { + s[k] = schema.ParserSetup{} + } + for fk, fv := range ftCfg { + s[k][fk] = fv + } + } + if rawAllowed, ok := params["allowed_output_format"].(map[string]any); ok { + ... + } } pc := &ParserComponent{Setups: s, Param: p} if err := pc.Check(); err != nil { return nil, fmt.Errorf("Parser: %w", err) } return pc, nil }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/ingestion/component/parser.go` around lines 133 - 176, Remove the early return for nil params in NewParserComponent so nil input follows the same construction and validation path as other inputs. Preserve the default p and s initialization, build ParserComponent, and always invoke pc.Check() before returning it, including when params is nil.internal/ingestion/component/parser_dispatch.go (1)
282-320: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick winRemove the legacy
"picture"/"visual"branches fromfamilyToExt.
pythonFamilyNamenow normalizes image families to"image", sofamilyToExt(pythonFamilyName(...))cannot hit those branches.♻️ Proposed cleanup
- case "picture", "image", "visual": + case "image": return utility.FileTypeVISUAL🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/ingestion/component/parser_dispatch.go` around lines 282 - 320, Remove the legacy "picture" and "visual" cases from familyToExt, since pythonFamilyName now normalizes both image families to "image". Leave the existing "image" mapping and all other family mappings unchanged.Source: Coding guidelines
🧹 Nitpick comments (2)
internal/ingestion/component/parser_dispatch_test.go (1)
852-898: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winConsider asserting the actual default value is whitelisted, not just key presence.
This test confirms
AllowedOutputFormat[got]exists but doesn't assert that the family's actual defaultoutput_format(e.g."json"for audio) is a member of that list. Strengthening this would directly close the open verification on whether"json"is permitted for audio (seeparser.goaudio default change).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/ingestion/component/parser_dispatch_test.go` around lines 852 - 898, Strengthen TestPythonFamilyName_FileTypeConstants by asserting that each family's configured default output_format is included in its AllowedOutputFormat whitelist, rather than only checking key presence. Reuse the corresponding defaults from defaultSetups() and the allowed values from schema.ParserParam{}.Defaults(), including validation that the audio default such as "json" is permitted.internal/ingestion/component/parser.go (1)
225-235: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueReplace
containsStringwithslices.Contains.Go 1.26 supports
slices.Contains, so this helper can be removed and the whitelist membership checks can use the stdlib implementation directly.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/ingestion/component/parser.go` around lines 225 - 235, Remove the local containsString helper and replace each whitelist membership check in Check() with the standard library slices.Contains call. Add the required slices import, preserving the existing list and value arguments and behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@internal/ingestion/component/parser_dispatch.go`:
- Around line 282-320: Remove the legacy "picture" and "visual" cases from
familyToExt, since pythonFamilyName now normalizes both image families to
"image". Leave the existing "image" mapping and all other family mappings
unchanged.
In `@internal/ingestion/component/parser.go`:
- Around line 133-176: Remove the early return for nil params in
NewParserComponent so nil input follows the same construction and validation
path as other inputs. Preserve the default p and s initialization, build
ParserComponent, and always invoke pc.Check() before returning it, including
when params is nil.
---
Nitpick comments:
In `@internal/ingestion/component/parser_dispatch_test.go`:
- Around line 852-898: Strengthen TestPythonFamilyName_FileTypeConstants by
asserting that each family's configured default output_format is included in its
AllowedOutputFormat whitelist, rather than only checking key presence. Reuse the
corresponding defaults from defaultSetups() and the allowed values from
schema.ParserParam{}.Defaults(), including validation that the audio default
such as "json" is permitted.
In `@internal/ingestion/component/parser.go`:
- Around line 225-235: Remove the local containsString helper and replace each
whitelist membership check in Check() with the standard library slices.Contains
call. Add the required slices import, preserving the existing list and value
arguments and behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b7d38fe9-224d-42ce-ad7c-3df815e7ad76
📒 Files selected for processing (8)
internal/ingestion/component/parser.gointernal/ingestion/component/parser_check_test.gointernal/ingestion/component/parser_dispatch.gointernal/ingestion/component/parser_dispatch_test.gointernal/parser/parser/office_parsers_no_cgo.gointernal/parser/parser/office_parsers_nocgo_test.gointernal/parser/parser/pdf_parser_nocgo.gointernal/parser/parser/pdf_parser_nocgo_test.go
Summary
Adds construction-time parameter validation to the ingestion
ParserComponent(mirroring the applicable subset of PythonParserParam.check()), fixes a family-mapping mismatch that silently skippedoutput_formatvalidation and setup configuration for image/audio files, and aligns the no-CGO parser stubs with the CGO variants by threadingcontext.ContextthroughParseWithResult.What changed
Parser component param check (
internal/ingestion/component/parser.go)(*ParserComponent).Check()method mirrors the applicable subset of PythonParserParam.check()(rag/flow/parser/parser.py:251-321):parse_method; non-whitelist values are treated as VLM methods and requirelang.ocrparse_methodrequireslang.NewParserComponentnow runsCheck()at construction time, so a malformed DSL surfaces as a canvas compile failure rather than a mid-run error.output_formatdefault changed fromtexttojsonto match the other media families.output_formatwhitelist — already enforced at Invoke time byresolveOutputFormat.vlm.llm_id— Gomedia_dispatchresolves tenant default models viaresolveTenantModelByType, notsetup["vlm"]["llm_id"]. Validating it would block every valid audio/video pipeline.Family mapping fix (
internal/ingestion/component/parser_dispatch.go)pythonFamilyNamenow maps the semanticFileTypeconstants to the actual setups keys:visual/picture→image(waspicture, mismatching thedefaultSetupskey, sooutput_formatvalidation andconfigureParserFromSetupswere silently skipped for image files)aural→audio(previously matched no case at all)video→videoandemail→emailnow also match theFileTypeVIDEO/FileTypeEMAILconstants directly.context.Contextthreading for no-CGO stubsParseWithResultonDOCXParser,DOCParser,PPTParser,PPTXParser,PDFParser(no-CGO variants) now acceptscontext.Context, aligning with the CGO variants.PDFParserthreadsctxintoparsePDFWithMinerU/parsePDFWithPaddleOCR/parsePDFWithDocling/parsePDFWithOpenDataLoader.Tests
parser_check_test.go(new): table-driven coverage forCheck()across PDF/image families, audio/video vlm omission, and empty/default configurations.parser_dispatch_test.go:TestPythonFamilyName_FileTypeConstantspins everyFileTypeconstant to its setups key, andTestConfigureParserFromSetups_VisualAuralpins that image/audio files pick up their setup.office_parsers_nocgo_test.go,pdf_parser_nocgo_test.go: updated for the newctxparameter.Backward compatibility
Check()runs at construction time and returns errors for malformed DSLs that previously failed silently at runtime or were silently mis-configured. Callers constructing pipelines from validated DSLs (e.g. the shippedingestion_pipeline_*.jsontemplates) are unaffected.ParseWithResultsignature change is internal to theparserpackage; no public API impact.output_formatdefault change (text→json) aligns with the other media families; pipelines that explicitly setoutput_formatare unaffected.