← Questions

Build a text summarization API service

0
MetaCodingLast asked Jan 2026

A coding interview question asked in Meta's AI-enabled coding round, last asked Jan 2026. It tests python, apis and llm.

Build a minimal but production-ready FastAPI service for text summarization. It exposes one endpoint, POST /summarize, that takes some text and returns a summary. The summarizer itself can be a placeholder function; you do not call a real model. Every request and its response are kept in memory. You present the file structure first, then the code for each file.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • POST /summarize with body {"text": string} returns 200 with {"summary": string}.
  • Empty or missing text, or a body that is not JSON, returns a 4xx with a clear error message.
  • An unexpected error inside the summarizer returns 500 with a generic message, and the error is logged.
  • Layers: a router (HTTP only), a service (summarization and storage), and Pydantic models for the request and the response.

Example

POST /summarize  {"text": "FastAPI is a modern web framework for Python. It is fast. It uses type hints."}
  ->  200  {"summary": "FastAPI is a modern web framework for Python."}   # placeholder: first sentence

POST /summarize  {"text": ""}
  ->  422  validation error: text must not be empty

POST /summarize  {"txt": "hello"}
  ->  422  validation error: field "text" is required

Constraints

  • Python with type hints throughout; Pydantic for validation.
  • No database: an in-memory store is enough.
  • Keep the code modular, readable and simple.

Clarifying questions

  • Is there a maximum text length?
  • Should the stored history be exposed, for example with GET /summaries?
  • Does the in-memory store need to be safe under concurrent requests?
  • Sync or async handlers?

What a strong answer covers

  • A clear layout, for example app/main.py, app/routers/summarize.py, app/services/summarizer.py, app/models/summary.py, tests/test_summarize.py.
  • Pydantic models with constraints (min_length=1, a maximum length, whitespace stripped) so validation happens before the handler runs.
  • The service injected with FastAPI's Depends, so tests can replace it.
  • In-memory storage behind a small repository class, with a lock if handlers can run concurrently, and a bound so memory cannot grow forever.
  • Error handling: HTTPException for known problems, an exception handler for unexpected ones, no stack traces leaked to clients.
  • Tests with TestClient: a good request, empty text, a missing field, the summarizer raising an error.

Follow-ups

  • Replace the placeholder with a real model call that can take several seconds. What changes in the API?
  • Add rate limiting per client.
  • How would you run this in production: workers, health check, logging, configuration?
  • The in-memory store must survive restarts and be shared across instances. What do you use?

Where it's asked

  • Meta · AI-enabled coding · Last asked Jan 202660 min · Several progressive tasks on a starter codebase in CoderPad with an AI assistant panel; usually two rounds · The first task usually without AI, later tasks with it

What it tests

python · apis · llm

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding