Skip to content

[BUG] extracted_urls field in DocumentResponse lacks field_validator, unlike keywords field #754

Description

@vipul674

Description of the Bug

In backend/app/schemas.py, the DocumentResponse model has two fields that are stored as JSON strings in the database but are handled inconsistently:

keywords field — has a @field_validator that automatically parses the JSON string:

@field_validator("keywords", mode="before")
@classmethod
def parse_keywords(cls, v):
    if isinstance(v, str):
        return json.loads(v)
    return v

extracted_urls field — has no field_validator:

extracted_urls: Optional[List[str]] = None

Instead, the route handler _deserialize_doc() in routes/documents.py manually parses extracted_urls:

if doc.extracted_urls:
    doc_data["extracted_urls"] = json.loads(doc.extracted_urls)

This inconsistency means:

  • Any code path that constructs DocumentResponse without going through _deserialize_doc() will receive the raw JSON string instead of a parsed list
  • If a new endpoint starts returning DocumentResponse directly, extracted_urls will be broken
  • The inconsistency is confusing and increases maintenance burden

Steps to Reproduce

  1. Upload a document that has extracted URLs
  2. Call an endpoint that returns DocumentResponse but doesn't use _deserialize_doc()
  3. The extracted_urls field contains a raw JSON string instead of a list

Expected Behavior

Both fields should be handled consistently. Add a @field_validator("extracted_urls", mode="before") to DocumentResponse similar to keywords.

Affected File

backend/app/schemas.py (lines ~135-146)

Suggested Fix

Add a field validator:

@field_validator("extracted_urls", mode="before")
@classmethod
def parse_extracted_urls(cls, v):
    if isinstance(v, str):
        return json.loads(v)
    return v

Then remove the manual parsing from _deserialize_doc() in the route handler.

GSSoC '26

  • Yes, I am participating in GirlScript Summer of Code and would like to fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gssocGirlScript Summer of Code 2026 issue/PR

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions