Can flatness be specified by a natural coherent sheaf?

More precisely:

Given a finite-type morphism $f \colon X \to Y$ of nice schemes (say, both of finite type over a field), is there a "natural" coherent sheaf $\mathcal F_f$ on $X$ such that the support of $\mathcal F_f$ is precisely $\{x \in X : f \text{ is not flat at }x\}$?

I'd rather not say what exactly "natural" should mean here, but if you held a gun to my head, I would guess it means that $\mathcal F_f$ is preserved under flat pullbacks; in other words, that if $g\colon Z \to Y$ is a flat finite-type morphism of nice schemes, then $\mathcal F_{f \circ g} = g^* \mathcal F_{f}$.

Example: If $X = \operatorname{Spec} B$, $Y = \operatorname{Spec} A$, and $A \to B$ is a local morphism of local noetherian rings, then $$\ker(B \otimes_A \mathfrak m \to B)$$ is a finitely generated $B$-module that is zero iff $B$ is flat over $A$ (by the local criterion for flatness). [Notation: $\mathfrak m$ is the maximal ideal of $A$.] This construction is respected under pullback by flat local morphisms $B \to C$ of local noetherian rings. Unfortunately, it runs into trouble if you look at flatness anywhere except the closed point of $\operatorname{Spec} B$.

Motivation: There are standard theorems that certain sets (including the one above) are "open," without really specifying a closed subscheme structure on the complement. In some cases, the complement can be described as the support of a coherent sheaf, which gives it a natural scheme structure. For instance, the "indeterminacy locus" of a rational function may be described by the cokernel of the ideal of denominators. I personally find such constructions more satisfying and memorable than more direct proofs that a particular subset is open.

-
Note that there is no such determination of the smooth locus either (correct me if I am wrong). – Damian Rössler Sep 8 '12 at 17:40
Damian: the cokernel of the right Fitting ideal can detect where a coherent sheaf is locally free. Under the right hypotheses (including the flatness of $X \to Y$), I believe the locus on which $\Omega_{X/Y}$ is locally free is precisely the smooth locus of the morphism. – Charles Staats Sep 8 '12 at 19:00
Note: in the comment above, "right" should probably be "correct." (There is a Fitting ideal for each $i$ that detects, roughly, whether the sheaf is locally generated by $i$ elements. The "right"/"correct" Fitting ideal is the one for which $i$ is equal to the relative dimension of $X$ over $Y$.) – Charles Staats Sep 8 '12 at 20:59
I see; but to have a smooth morphism, it has to be flat to begin with. You cannot detect that on $\Omega_{X/Y}$ unless maybe you assume that $X$ and $Y$ are smooth over an alg. closed field and $\Omega_{X/Y}$ has the right rank. In the context of your question, have you thought of looking in the paper of Raynaud-Gruson "Critère de platitude..." esp. the proof of th. 3.4.6 (which doesn't answer your question but might give you ideas) ? – Damian Rössler Sep 9 '12 at 9:24

Assume the morphism $f$ is projective. Let $L$ be a relatively ample line bundle on $X$. Then there is such $N$ that the nonflatness locus of $f$ coincides with the locus where $F := f_*(L^N)$ is not locally free. If additionally $Y$ is smooth the latter is the union of supports of the sheaves ${\mathcal Ext}^i(F,O_Y)$, $i>0$.